Thursday 13 August 2015

How do you get a timestamp in JavaScript?

How do you get a timestamp in JavaScript?

Question: What is timestamp?
timestamp is the current time of an event that is recorded by a computer. In JavaScript, it gives local time (computer ).


Question: How do you get a timestamp in JavaScript?
Date.now()



Question: How do you get a timestamp in number of seconds?
Math.floor(Date.now() / 1000)



Question: How do handle exception to this is IE8 and other Browser?

if (!Date.now) {
Date.now()
}



Question: How do you get the date from the time object
new Date().getDate()



Question: What are other date-functions in javascript?
getDate(): Get the day as a number (1-31)
getDay(): Get the weekday as a number (0-6)
getFullYear(): Get the four digit year (yyyy)
getHours(): Get the hour (0-23)
getMilliseconds(): Get the milliseconds (0-999)
getMinutes(): Get the minutes (0-59)
getMonth(): Get the month (0-11)
getSeconds(): Get the seconds (0-59)
getTime(): Get the time (milliseconds since January 1, 1970)