Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery convert number to date? [duplicate]

Tags:

jquery

time

epoch

i have a json file that returns "date_created":"1273185387" in epoch format

i want to convert it to something like this Thu, 06 May 2010 22:36:27 GMT

any script to do this conversion?

like image 759
Patrioticcow Avatar asked Apr 19 '11 21:04

Patrioticcow


People also ask

How to convert number to date in jQuery?

var dt = new Date(obj. date_created * 1000);

How do you convert a number into a date?

Select the cells that have the number that you want to convert into a date. Click the 'Home' tab. In the 'Number' group, click on the Number Formatting drop-down. In the drop-down, select 'Long Date' or Short Date' option (based on what format would you want these numbers to be in)

How do I convert a number to a date in TypeScript?

Use the Date() constructor to convert a string to a Date object in TypeScript, e.g. const date = new Date('2024-07-21') . The Date() constructor takes a valid date string as a parameter and returns a Date object.


2 Answers

var myObj = $.parseJSON('{"date_created":"1273185387"}'),     myDate = new Date(1000*myObj.date_created);  console.log(myDate.toString()); console.log(myDate.toLocaleString()); console.log(myDate.toUTCString()); 

http://jsfiddle.net/mattball/8gvkk/

like image 135
Matt Ball Avatar answered Nov 06 '22 03:11

Matt Ball


alert(new Date(1273185387).toUTCString()); 
like image 45
Dustin Laine Avatar answered Nov 06 '22 04:11

Dustin Laine