gafasmill gafasmill - 1 year ago 103
Javascript Question

Javascript date formate conversion issue

I have this code:

click: function () {

datevalue = (this.x); //Returns 198

var dateTimeString = moment(datevalue).format("DDMMY"); //Returns 01011970


My problem is that dateTimeString is returning the format as 01011970 (so... 01-01-1970) and I need it to return the year in just 2 digits (70 in the case).

I've tried .format("DDMMY") and .format("DDMMyy") but none of them work.

How can I fix this?

mmm mmm
Answer Source

I've tried .format("DDMMY") and .format("DDMMyy")

Why would you do this? You want the year only, not the day and month.

Just format in the format you want:

var dateTimeString = moment(datevalue).format("YY");

According to your comment above, try

var dateTimeString = moment(datevalue).format("DDMMYY");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download