Javascript – Get Current Date and Time

The following Javascript example shows you how to manipulate the Date object.

<script language="JavaScript">
  var x = new Date()
  var y = x.getFullYear()
  var m = x.getMonth()+1  // added +1 because javascript counts month from 0
  var d = x.getDate()
  var h = x.getHours()
  var mi = x.getMinutes()
  var s = x.getSeconds()
  alert(y+'-'+m+'-'+d+' '+h+':'+mi+':'+s)
</script>

 

Reference:

2 thoughts on “Javascript – Get Current Date and Time”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.