admin管理员组文章数量:1181401
I am new to typescript and this might be something very trivial. Please help.
I am trying to extract minutes and seconds from typescript Date variable. I have a variable timestamp declared as Date. But when I try to use functions on it like toDateString() or getMinutes() or getTime(), I get the above error saying TypeError: timestamp.getMinutes() is not a function.
Thanks.
I am new to typescript and this might be something very trivial. Please help.
I am trying to extract minutes and seconds from typescript Date variable. I have a variable timestamp declared as Date. But when I try to use functions on it like toDateString() or getMinutes() or getTime(), I get the above error saying TypeError: timestamp.getMinutes() is not a function.
Thanks.
Share Improve this question edited Feb 26, 2018 at 6:22 Andrew Eisenberg 28.7k9 gold badges96 silver badges151 bronze badges asked Feb 25, 2018 at 17:45 NoviceNovice 1731 gold badge1 silver badge7 bronze badges 1- Is this a compile time error ? – Titian Cernicova-Dragomir Commented Feb 25, 2018 at 17:48
3 Answers
Reset to default 27It's likely that your timestamp is not a date, just a number that represents the number of milliseconds since the Unix epoch.
All you need to do is convert your timestamp to a Date, like this:
let currentDate = new Date(timestamp);
Then you can call any Date
functions you want on it.
You can use the Angular DatePipe to achieve this-
{{current_date | date: 'shortTime'}}
You can find more information here - https://angular.io/api/common/DatePipe
toDateString() is not a function is showing because u may used it with any variable
toDateString() is a method which can be used with a date object only
本文标签: javascriptTypescript TypeError toDateString is not a functionStack Overflow
版权声明:本文标题:javascript - Typescript TypeError: ......toDateString is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738157331a2066430.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论