Search results
Results from the WOW.Com Content Network
Well, what I wanted was to convert today's date to a MySQL friendly date string like 2012-06-23, and to use that string as a parameter in one of my queries.
It sad but it is simpliest way to format js date to string you need. I'm new in js, but in java it is 100 times easier to format date to any format. That is why was thinking there are easier way, but after I tried different solutions I choose this one. Thank you for your answer. –
// use formatToParts() to convert a date and put it into an array for the different parts of the date var customDateArray = new Intl.DateTimeFormat('en-US', { day ...
I'm trying to use JS to turn a date object into a string in YYYYMMDD format. Is there an easier way than concatenating Date.getYear(), Date.getMonth(), and Date.getDay()?
Solutions Bd,Cd,Ct not return js Date object as results, but I add them because they can be useful but I not compare them with valid solutions. This results can be useful for massive date parsing. Conclusions. Solution new Date (Ad) is 50-100x faster than moment.js (Dd) for all browsers for ISO date and timestamp
In JS there are no simple and cross platform ways to format local date time, outside of converting each property as mentioned above. Here is a quick hack I use to get the local YYYY-MM-DD. Note that this is a hack, as the final date will not have the correct timezone anymore (so you have to ignore timezone).
You can use the following method to convert any js date to UTC: let date = new Date(YOUR_DATE).toISOString() // It would give the date in format "2020-06-16T12:30:00.000Z" where Part before T is date in YYYY-MM-DD format, part after T is time in format HH:MM:SS and Z stands for UTC - Zero hour offset
If you're using Node.js, you're sure to have EcmaScript 5, and so Date has a toISOString method. You're asking for a slight modification of ISO8601:
There are a huge number of questions on how to format a date, please try to write your own code then ask if you have issues. The use of Date.parse in new Date(Date.parse(string)) is redundant, new Date(string) will produce an identical result. –
@pceccon Answer to an old question for future readers, but the format should have been ("yyyy-MM-dd"). The library is case sensitive since you need to distinguish between minutes / month and 12 / 24 hour formats.