I want to set the time to the 1st January 0000 and time at 00:00:00 i tried to calculate a lot but i’m unable to set the date to the beginning point. I am setting the date with negative sign like this – new Date(-4000) but setting the year to 0 gives me only the 1900 so how can get to the perfect date of 1st Jan 0000 and time at 00:00:00. Answer The way you were doing you can also set it, to -62167219200000 it will return the same results as new Date(“0000-01-01”) Only will set the date to
I need to parse a date in the “it” locale with momentjs, and I’m doing this What I get is “invalid date” and I don’t understand why. Can you help me? Using the “en” locale (with the date written as 12/20/2018) all is ok Answer The below snippet will accomplish what you want. It takes moment’s date format for a given local and passes it to the constructor when creating a moment. With that said, the comments above raise a lot of good points and this is not a reliable way to be handling dates. For example, if someone in
This is a noob question: How to parse a date in format “YYYYmmdd” without external libraries ? If the input string is not in this format I would like to get invalid Date (or undefined if it will be easier). Answer Usage: UPDATE: As Rocket said, months are 0-based in js…use this if month’s aren’t 0-based in your string UPDATE: More rigorous checking for validity of date. Adopted HBP’s way to validate date.