Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Date.toString() formatting? [duplicate]

Possible Duplicate:
Formatting a date in JavaScript

I have the following piece of script. It's a HTML5 slider with a date range. The slider is using a unix timestamp and I want to display the current selection in a readable format.

This is working fine but is outputting as "Wed May 16 2012 08:07:30 GMT+0100 (GMT Daylight Time)" despite me specifying the format as "yyyy-MM-dd HH:mm:ss".

Any ideas why it's not outputting in my format?

<input id="slider3" type="range" min="1337149800" max="1337160600"
  step="450" onchange="printValue('slider3','rangeValue3')"/>
<input id="rangeValue3" type="text" size="90"/>

<script>
function printValue(sliderID, textbox) {
  var x = document.getElementById(textbox);
  var y = document.getElementById(sliderID);

  var d1=new Date(y.value*1000);

  var newtimestamp = d1.toString("yyyy-MM-dd HH:mm:ss");

  x.value = newtimestamp;
}
</script>
like image 680
user1107685 Avatar asked Sep 09 '25 11:09

user1107685


1 Answers

JavaScript's Date object does not support that. There's plenty of libraries to do this for you.

like image 112
Daniel A. White Avatar answered Sep 11 '25 00:09

Daniel A. White