Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  67] [ 5]  / answers: 1 / hits: 91304  / 12 Years ago, wed, september 5, 2012, 12:00:00

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>

More From » date

 Answers
75

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


[#83228] Tuesday, September 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
whitney

Total Points: 642
Total Questions: 110
Total Answers: 98

Location: Solomon Islands
Member since Mon, Jun 20, 2022
2 Years ago
;