Shawn Miller

JavaScript DateTime

December 02, 20067:02 AM
kick it on DotNetKicks.com

Do you hate the JavaScript Date class as much as we do?

getMonth() returns the month from 0 to 11... the unfortunately named getDate() returns the day of the month from 1 to 31... getDay() returns the day of the week from 0 to 6.

There are inconsistencies everywhere.  No obvious support for date arithmetic such as AddDays(), AddMonths().  And most painful is the lack of string formatting options... just try to format a date that looks like: 4/17/2006 2:22 PM.

This is why we've added a new class to Fresh Logic Studios Scripts.  The new DateTime class mimics the DateTime class of the .NET Framework and most importantly provides a variety of ways to format DateTime strings.  We'll keep expanding on this in the future to support more and more of the .NET DateTime format strings... coming soon support for RFC1123.