Javascript: Basic Date Object for Quick Reference

Here’s an exercise to create a new date object and convert today’s parts into the more human-readable month/day/year format. It’s not built into the Javascript language, what can you do?! Here’s a breakdown of some of the main methods built into the Date class, just the main ones

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January starts at ZERO, don't ask why
var yyyy = today.getFullYear();

if(dd<10) {   dd='0'+dd} 
if(mm<10) {   mm='0'+mm} 

today = mm+'/'+dd+'/'+yyyy;

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *