Date objects are created with the Date() constructor.
There are four ways of instantiating a date:
new Date() // current date and timeDate(dateString)
new Date(milliseconds) //milliseconds since 1970/01/01
new Date(dateString)
new Date(year, month, day, hours, minutes, seconds, milliseconds)
This Date constructor only accepts dateString in UTC format.
However, we can write our custom function that accepts a custom format, say dd/mm/yyyy, from which we can extract the date parts and use them to construct a Date object.
function parseDate(input, format) {Usage
format = format || 'dd/mm/yyyy'; // somedefault format
var parts = input.match(/(\d+)/g),
i = 0, fmt = {};
// extract date-part indexes from the format
format.replace(/(yyyy|dd|mm)/g, function(part) { fmt[part] = i++; });
return new Date(parts[fmt['yyyy']], parts[fmt['mm']]-1, parts[fmt['dd']]);
}
parseDate('01-31-2010', 'mm-dd-yyyy');
parseDate('31/01/2010', 'dd/mm/yyyy');
parseDate('2010/01/31');
4 comments:
Nice post.
istartus.com aim is to promote your website through the use of E-Marketing services.We provide full service Web Design, Development and Hosting.
I genuinely appreciated understanding it. Sitting tight for some more incredible articles like this from you in the nearing days.
Tableau Training in Pune
Best Tableau Training Institute in Pune
Excellent blog!!! I got to know more useful information by reading your blog. Thanks for posting this blog.
Tableau Training in Pune
Best Tableau Training Institute in Pune
Post a Comment