1

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?

  • Possible duplicate of [Convert date into dd/MM/yyyy format in JQuery](http://stackoverflow.com/questions/3965365/convert-date-into-dd-mm-yyyy-format-in-jquery) – Saurabh Srivastava Oct 02 '16 at 05:45

3 Answers3

3

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);
guest271314
  • 1
  • 15
  • 104
  • 177
0

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"));
jrbedard
  • 3,662
  • 5
  • 30
  • 34
  • 1
    After executing new Date("1475173800000"), myDate is having value as invalidDate. Checked it just now while debugging. –  Oct 02 '16 at 04:49
  • 1
    Added `parseInt` to convert timestamp string to integer. – jrbedard Oct 02 '16 at 05:14
0

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.

Chintan Palan
  • 1,016
  • 1
  • 10
  • 15