当前位置:网站首页>Using parseInt() in TypeScript
Using parseInt() in TypeScript
2022-08-10 06:14:00 【um senson】
When using angular to write something, you need to use the parseInt() method to convert the timestamp into the format of hours, minutes and seconds (xx hours-xx minutes-xx seconds), but because angular uses Typescript, and
parseInt(string:string,radix?:number):number
The first parameter passed in parseInt is of type string, so using parseInt will report an error
Parameter of type 'number' cannot be assigned to parameter of type 'string'.
I searched for a long time, and after thinking for a long time, I finally found it after I came up with a solution...
We can use the toString() method in the passed parameters to convert the passed parameters to string type
let hours:any = parseInt(((timeSpend % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)).toString());let minutes:any = parseInt(((timeSpend % (1000 * 60 * 60)) / (1000 * 60).toString());
That's it!!!
PS: Of course, you can use Math.floor() to solve it (the first method was found on the Internet after I thought of it, and the second method was found on the Internet)
边栏推荐
猜你喜欢
pytorch-10. Convolutional Neural Networks (homework)
以STM32F103C6TA为例通过配置CubeMX实现GPIO输出完成点灯实例
系统架构和问题定位
STM32F407ZG TIM通用定时器
【fiddler4】使用fiddler设置简单并发
51单片机RS485远程双机多机温度采集主从机多节点蜂鸣器报警
以STM32F103C6T6为例通过配置CubeMX实现EXIT外部中断
51单片机室内环境甲醛PM2.5光照温度湿度检测及窗帘加湿消毒控制系统
通过adb devices命令在控制台显示企业级PicoNeo3设备号
新建STM32F407ZG Keil5项目
随机推荐
STM32单片机OLED经典2048游戏单片机小游戏
手把手教你改内核源码--sysfs虚拟文件系统1
STM32F407ZG PWM
氨氮吸附工艺
【接口自动化】
开源游戏服务器框架NoahGameFrame(NF)服务器端环境搭建(二)
在Unity的Update中通过物体自身位置判断运动方向
详解 Hough 变换(下)圆形检测
溶液中重金属去除
pytorch-10. Convolutional Neural Networks (homework)
markdown类图学习
剑指 Offer(第 2 版)7/5 5-8
从零开始构建Google Protocol Buffer / protobuf 的helloworld工程(超级详细)
手机端应用类型
二次元卡通渲染之描边
ASP.Net利用代码点击相应按钮来关闭当前的页面(亲测有效)
【C语言】结构体变量学习笔记1
初学者也能看懂的Ray March体积云
51单片机RS485远程双机多机温度采集主从机多节点蜂鸣器报警
21天学习挑战赛--补种胡杨求最大连续胡杨数量