DateTime.js
Extends the Date functions by using prototype. Usefully when you want to perform some date calculations.
Enter a date, or select a date form the pop up calender, to see how the fuctions return the values of the date entered. Tab or click out of the "Test Date" field to activate functions.
Test Date (mm/dd/yyyy)
 Click here for a calendar.
Function Name Returns Description
weekNumber() Week number in the year (ie., 27)
daysInMonth() Total days in a month (ie., 31)
daysInQuarter() Total days in a quarter (ie., 92)
dayOfYear() Total days elasped in a year (ie., 182)
daysLeftInYear() Total days remaining is a year (ie., 183)
daysInYear() Total days is a year (ie., 365)
isLeapYear() 1 or 0
Date Format
dateFormat()
Formats date, based on the mask.
Format
Language

Result 
Date Format Examples
Object Names Returns Description
dateFormat('DDDD') Full day name (ie., Tuesday)
dateFormat('MMMM') Full month name (ie., July)
dateFormat('d') Day number and a prefix (ie., 1st) Highest number 31
dateFormat('Q') Quarter number (ie., 3)
dateFormat('q') Quarter number and a prefix (ie., 3rd)
dateFormat('YYYY') 4 digit year (ie., 2003)
Time Zone
getTimeZone()
Gets time zone data based on user's system time zone.
Note: To change time zones. Open your date and time settings and change the time zone then reload.
getTimeZone Object Results
Object Names Returns Description
offset Time zone offset. (ie., -0000)
gmtStr Time zone offset with "GMT" text. (ie., GMT+0000)
timeZonesLen timeZones array length
timeZones array object of time zones
  (ie., see below: name and abr)
timeZones Object Results
timeZones[n].name List of names in this time zone. Where "n" is the array index.
timeZones[n].abr List of abbreviations in this time zone. Where "n" is the array index.
Miltary Time Zone
getTimeZoneMiltary()
Gets Miltary time zone data based on user's system time zone.
Note: To change time zones. Open your date and time settings and change the time zone then reload.
getTimeZoneMiltary Object Results
Object Names Returns Description
offset Time zone offset. (ie., -0000)
gmtStr Time zone offset with "GMT" text. (ie., GMT+0000)
name Miltary time zone full name.
abr Miltary time zone abbreviation .
Julian Date
julianDate() Julian Date (ie., 2454267.8982)
Date Differance
dateDiff(type, begin_date, end_date, rounding_off)
Returns differance of two dates
Type
Begin Date (mm/dd/yyyy)
 Click here for a calendar.
End Date (mm/dd/yyyy)
 Click here for a calendar.
 Round to the nearest whole number.

Result  Differance of "" between the two dates entered above.
Date Calculation
dateCal(type, number, date, language)
Returns object of future/past date based on number entered. For past date use a negative number.
Type
Number
Test Date (mm/dd/yyyy)
 Click here for a calendar.
Language
Date Calculation Object Results
Object Names Returns Description
YYYY 4 digit year (ie., 2003)
M Month number (1-12)
D Day number (1-31)
DDDD Day Name
DDD Day Name Abbreviation
H Hour number (0-23)
m Minute number (0-59)
s Second number (0-59)
val Date value in milliseconds
raw Raw date object. Can use any date object functions with this.
Existing Date Functions
getYear() Number of years since 1900
getFullYear() 4 digit year (ie., 2003)
getMonth() Month within year (0-11)*
getDate() Date within month (1-31)
getDay() Day within week (0-6)*
getHours() Hour within day (0-23)
getMinutes() Minutes within hour (0-59)
getSeconds() Seconds within minute (0-59)
getTime() Number of milliseconds since 1/1/1970 00:00:00
getTimezoneOffset() Minutes offset from GMT/UTC
toGMTString() Date string in universal format
toLocaleString() Date string in local system's format
* 0 index
Click here to see dateTime.js file.

 

Rate and/or tell us what you think of this demo.
Report a bug
Comments (Optional)