当前位置:网站首页>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)
边栏推荐
猜你喜欢
随机推荐
屏幕后期处理之:Sobel算子实现边缘检测
clickhouse出现数据重复问题
动态规划、背包问题 6/23 101-105
二叉树 6/16 81-85
21天学习挑战赛--补种胡杨求最大连续胡杨数量
剑指 Offer(第 2 版)7/7 14-17
抛光树脂应用
mysql分组排序并取各分组前几个数据
【fiddler2】使用fiddler mock response 数据
最简单的字符设备驱动
KDE框架介绍
lua的模块与类
51单片机BH1750智能补光灯台灯光强光照恒流源LED控制系统
STM32单片机手机APP蓝牙高亮RGB彩灯控制板任意颜色亮度调光
内核映像文件格式
计算数字区间中数字出现次数
常用模块封装-csv文件操作封装
21天学习挑战赛--图像物体的边界
Gradle学习(二)Groovy
电镀废水除六价铬