Issue
i have a job for converting a string into date in TypeScript
When i tried to convert "2022-07-01" like "yyyy-MM-dd" by this code
let temp = '2022-07-01';
let date = new Date(temp);
It returned this value "Fri Jul 01 2022 07:00:00 GMT+0700"
But When my string is "2022-07-01 01" like "yyyy-MM-dd hh" . It turned "Invalid Value"
So my question is how can i convert ''yyyy-MM-dd hh" to Date in typeScript and can i change gmt when i convert Date? Thanks
Solution
Easiest solution is to set a default minutes part
let temp = '2022-07-01 01';
temp += ':00';
let date = new Date(temp);
if you need to change the timezone you must to pass all the date like this:
new Date("2015-03-25T12:00:00Z");
Answered By - btafarelo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.