user6422990
user6422990

Reputation:

How to convert a DateTime value to dd/mm/yyyy in jQuery?

I am having a datetime object whose value is: /Date(1475173800000)/ in jQuery. I want it to be displayed in dd/mm/yyyy in jQuery. Is there any way to achieve it?

Upvotes: 1

Views: 14964

Answers (3)

Chintan Palan
Chintan Palan

Reputation: 1106

One of the easiest things to use for date is datejs (http://www.datejs.com/) You can use the toString method to provide the format in which you want to get the date. There are much more useful components for date manipulation in this library. Do check it out.

Upvotes: 0

jrbedard
jrbedard

Reputation: 3730

Try jQuery dateFormat for easy and flexible date formatting. You simply use it like this:

var timestamp = /\/Date\((.*)\)\//;
var myDate = new Date(parseInt(timestamp));
$.format.date(myDate.getTime(), "dd/mm/yyyy"));

Upvotes: 0

guest271314
guest271314

Reputation: 1

You can use new Date() with parameter being universal time variable, Date.prototype.toJSON(), String.prototype.slice(), String.prototype.split() with parameter "-", Array.prototype.reverse(), Array.prototype.join() with parameter "/"

var time = 1475173800000;
    
var date = new Date(time).toJSON().slice(0, 10).split("-").reverse().join("/");

console.log(date);

Upvotes: 3

Related Questions