O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Time String

var d = new Date(); d.toLocaleTimeString() 1:55:13 PM d.toTimeString() 13:55:13 GMT-0600 (Mountain Daylight Time)

The Date object also allows you to get just a time string. There are two methods attached to the Date object that return a time string. The .toTimeString() method returns a time string with the time, time zone, and even daylight savings time information. The .toLocaleTimeString() returns a more basic time string with local formatted time.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required