Skip to content
Advertisement

Tag: date

How to parse a date in format “YYYYmmdd” in JavaScript?

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:

Getting current date and time in JavaScript

I have a script that prints the current date and time in JavaScript, but the DATE is always wrong. Here is the code: It should print 18/04/2012 15:07:33 and prints 3/3/2012 15:07:33 Answer .getMonth() returns a zero-based number so to get the correct month you need to add 1, so calling .getMonth() in may will return 4 and not 5.

Javascript library for human-friendly relative date formatting [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 7 years ago. Improve this question I’d like to display some dates as relative to the current

Get the current year in JavaScript

How do I get the current year in JavaScript? Answer Create a new Date() object and call getFullYear(): Example usage: a page footer that always shows the current year: See also, the Date() constructor’s full list of methods.

Convert string to datetime

How to convert string like ’01-01-1970 00:03:44′ to datetime? Answer For this format (assuming datepart has the format dd-mm-yyyy) in plain javascript use dateString2Date. It may bite you, because of browser compatibility problems. tryParseDateFromString is ES6 utility method to parse a date string using a format string parameter (format) to inform the method about the position of date/month/year in the

Advertisement