javascript get formated date time

There is no date time format function for javascript not using external libs. You have to do it yourself.
Here an examples for french format YYYY-mm-dd_HH:mm:ss

var curr = new Date();
var year = curr.getFullYear();
var month = (((curr.getMonth()+1) < 10)?'0:'') + (curr.getMonth()+1)
var day = ((curr.getDate() < 10)?'0':'')+curr.getDate()
var hour = ((curr.getHours() < 10)?'0':'')+curr.getHours()
var minute = ((curr.getMinutes() < 10)?'0':'')+curr.getMinutes()
var seconde = ((curr.getSeconds() < 10)?'0':'')+curr.getSeconds()

var output = year+'-'+month+'-'+day+'_'+hour+':'+minute+':'+seconde;

Leave a Reply