当前位置:网站首页>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):numberThe 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)
酸回收工艺讲解
STM32F407ZG TIM通用定时器
碳酸锂、碳酸氢锂溶液除钙镁离子工艺原理
【图像识别】训练一个最最简单的AI使其识别Vtuber
C#热更新比Lua好在哪里?
常用模块封装-csv文件操作封装
每日刷题(day02)——leetcode 622. 设计循环队列
工业废酸回收工艺
二维卷积定理的验证(下,cv2.filter2D())
所有文章汇总目录
GC0053-STM32单片机NTC热敏电阻温度采集及控制LCD1602
样条曲线(下)之插值问题(贝塞尔曲线、B样条和一般样条曲线插值)
内核映像文件格式
Tensorflow 2.0 使用流程详解
浅谈游戏中3种常用阴影渲染技术(1):平面阴影
剑指 Offer(第 2 版)7/6 9-13
Unity对象池实现
为什么游戏需要热更新?
51单片机室内环境甲醛PM2.5光照温度湿度检测及窗帘加湿消毒控制系统









