JavaScript Date Object also provides the functions to get the parts of current time. To get the Time parts such as hours, minutes, seconds and milliseconds you can define a variable for Date Object using new keyword. This will provide all the methods for retrieving the parts of the Time as well as Date, from which you can use Time related functions to work upon.

JavaScript Date Object Methods to retrieve the Time Parts

getHours() getHours function returns the current Hour of Time retrieved using Date Object range from 0 to 23.

getMinutes() getMinutes function returns the current minute of Time retrieved using Date Object range from 0 to 59.

getSeconds() getSeconds function returns the current second of Time retrieved using Date Object range from 0 to 59.

getMilliseconds() getMilliseconds function returns the milli seconds of Time retrieved using Date Object range from 0-999.

getTimezoneOffset() getTimezoneOffset returns the difference between current local time and Greenwich Mean Time in minutes.

JavaScript code Example to retrieve Time Parts using Date Object

// Date object defined with new keyword.
var myDate = new Date();

// JavaScript getHours Function
document.write(myDate.getHours());

// JavaScript getMinutes Function
document.write(myDate.getMinutes());

// JavaScript getSeconds Function
document.write(myDate.getSeconds());

// JavaScript getMilliseconds Function
document.write(myDate.getMilliseconds());

// JavaScript getTimezoneOffset Function
document.write(myDate.getTimezoneOffset());

You can divide the getTimezoneOffset with 60 to get the GMT difference in hours. It will return the hours in +/- according to your country.

Continue to next tutorial: Javascript Convert String to Date to learn how to convert the string type value having valid date format into  date type and apply JavaScript Date Object functions over it.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.