Converting milliseconds to a date (jQuery/JavaScript)
var time = new Date().getTime(); // get your number
var date = new Date(time); // create Date object
console.log(date.toString()); // result: Wed Jan 12 2011 12:42:46 GMT-0800 (PST)
How to Convert Milliseconds to Date in JS?
var d = new Date(+milliseconds);
How to convert milliseconds into a readable date?
Using the library Datejs you can accomplish this quite elegantly, with its toString
format specifiers: http://jsfiddle.net/TeRnM/1/.
var date = new Date(1324339200000);
date.toString("MMM dd"); // "Dec 20"
How to convert milliseconds to date and time?
Date
's constructor takes a number, not a string. Either feed it in directly:
date = 1475235770601; // Note the lack of quotes making it a number
Or, if you already have a string, convert it explicitly:
date = parseInt(date);
convert from milliseconds to date format in javascript
var milliseconds = new Date().getTime(); //Get milliseconds
var date = new Date(milliseconds); // Create date from milliseconds
console.log(date.toString()); //Log: Fri Feb 05 2016 12:41:18 GMT+0200 (EET)
// Let's create futureDate, 5days after now ...
var millisecondsInDay = 8.64e+7; // Milliseconds per day
var futureDate = new Date(milliseconds + 5*millisecondsInDay);
console.log(futureDate.toString()); //Log: Wed Feb 10 2016 12:41:18 GMT+0200 (EET)
How to convert milliseconds to a readable date with Javascript?
JavaScript doesn’t have built-in date formatting. You can do it yourself, but there are also a few libraries out there.
function pad(s, width, character) {
return new Array(width - s.toString().length + 1).join(character) + s;
}
var maxDate = new Date(1407267771429);
var maxDateFormatted =
maxDate.getFullYear() +
' ' + pad(maxDate.getMonth() + 1, 2, '0') +
' ' + pad(maxDate.getDate(), 2, '0');
Related Topics
Decoding Url Parameters with JavaScript
How to Combine Jquery Animate with CSS3 Properties Without Using CSS Transitions
Using JavaScript to Increment Top/Left/Bottom/Right Values
Ckeditor: Class or Id for Editor Body
Restart a Gif Animation Without Reloading the File
Why Does Reflow Need to Be Triggered for CSS Transitions
Get All Computed Style of an Element
Dynamically Add CSS to Page via JavaScript
Fix First Column of a Bootstrap Table
How to Get Color Value from Gradient by Percentage with JavaScript
Affix Is Not Working in Bootstrap 4 (Alpha)
Jquery/JavaScript Opacity Animation with Scroll
Clean Way to Programmatically Use CSS Transitions from Js
Center an Image Vertically and Horizontally Using CSS
Set Height of <Div> = to Height of Another <Div> Through .Css
How to Get a Floating Footer to Stick to the Bottom of the Viewport in Ie 6
Close a Div by Clicking Outside
How to Destructure All Properties into the Current Scope/Closure in Es2015