From the course: JavaScript for Web Designers

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Get pieces of time

Get pieces of time

- Now we're going to look at some of the other methods that are available on the built-in date object so we can format our time a little more nicely than this. I'm going to open up the Javascript console to experiment with this. So hit cmd + opt + i here, open up the console, clear these messages. First I'm going to give myself a date object to play with, so I'm going to create this with the name of D, just like I have before, the new date, and this returns a date object. Now remember that we have the string version of this, so toTimesString. So if I wanted to start to do some reformatting of this, I could consider just trimming off everything that comes after that, so we could save this as a string, toTimesString, and then I could use the substring method and just take off everything up to, say, the eighth character. That would give me this, but it's still just a string. Instead of kind of twiddling around…

Contents