I want to convert the returned value of new Date to UTC format using moment js.
I tried using moment.utc but
moment.utc(moment(new Date())).format();
output -> 2020-01-01T04:00:00Z
but I want output in this format
Thu Jun 04 2020 00:00:15 GMT+0530 (India Standard Time)
just like what new Date returns but it should be in UTC.
and the other problem is that the return type of format is of
TYPE : STRING I want that the format should be the same but its type should be of date object.
Any help would be appreciated.
Related
I have the following date format : 2020-09-25T11:09:00.422Z, which in order to be processed, needs to be modified to the following format: Wed Apr 01 2015 00:00:00 GMT+0100
How to achieve that in a one liner ?
Thanks
Create a Date instance and pass the value as string:
new Date("2020-09-25T11:09:00.422Z")
I need to create javascript object with timezone CST/CDT, below line of code is working fine in chrome but not on firefox
new Date("2020-06-06 05:37:34.0" + ' CST/CDT');
chrome result:
Sat Jun 06 2020 15:37:34 GMT+0500 (Pakistan Standard Time)
firefox result:
Invalid Date
need suggestions to fix it.
Always try to use UTC dates, meaning storing and performing calculations on Dates as UTC.
If you want to create a Date object specific to the timezone, do the below, I have shown how it can be converted back to UTC/local time zone:
const date = new Date('2010-05-11T10:11:00-0500');//CDT time
console.log(date.toString()); //date as per the current timezone of the machine this code is executed => "Tue May 11 2010 20:41:00 GMT+0530 (India Standard Time)"
console.log(date.toISOString());//converts the Date as UTC based ISO date string => "2010-05-11T15:11:00.000Z"
I have a string 2016-01-04T15:30:00 coming from c# DateTime.
When I convert it to a javascript
Date object var jDate = new Date(2016-01-04T15:30:00);
the time is getting changed based on the local time zone
Console Output: Mon Jan 04 2016 10:30:00 GMT-0500 (Eastern Standard Time)
How can I get the date to have the time 15:30 and not 10:30?
The answer should return a Date object so I can do date.getHours()
You need to cahnge the DateTime Kind to Unspecified,
DateTime.SpecifyKind(saveNow, DateTimeKind.Unspecified);
Read more here :
https://msdn.microsoft.com/en-us/library/system.datetime.specifykind(v=vs.110).aspx
The question is simple, I use momentjs to get the current date of the system, in particular this is the date returned:
Sun Jan 03 2016 17:17:00 GMT+0100 (ora solare Europa occidentale)
I want convert this date in this format like this:
03/01/2016 17:17:00
How I can achieve this?
This is my code:
moment(new Date()).toDate()
You can use momentjs's format() function to format the date. As an example:
moment.locale('it');
moment(new Date()).format('dddd MM/DD/YYYY h:mm:ss');
This returns the date as "Domenica 01/03/2016 10:17:49"
In my javascript i want to convert date from date string.
i have string like
date = "Thu Sep 03 2015 19:30:00 GMT+0000"
Now i convert string using Date object.
var d = new Date(date);
But this gives me,
Fri Sep 04 2015 01:00:00 GMT+0530 (IST)
It automatically add one day into day. What is wrong?
It automatically add one day into day. What is wrong?
Nothing. The time you input is 19:30 GMT and the timezone on the device you're using is set to GMT+0530. Add 5 hours 30 minutes to 7:30pm and you get 01:00am the following day.
You should not use the Date constructor to parse strings, as it is inconsistent across browsers and until recently, entirely implementation dependent. Manually parse strings, or use a Date library.