/ UziTech / js-date-format

Add format method to Date object in javascript to allow string formatting

Download as .zip Download as .tar.gz View on GitHub

Introduction

Add formatting functions to a Date object

Usage

Adds the following methods to a date object:

getMonthName([language])

Gets the month name. (eg. January)

getMonthNameShort([language])

Gets the abbreviated month name. (eg. Jan)

getDayName([language])

Gets the day of the week name. (eg. Sunday)

getDayNameShort([language])

Gets the abbreviated day of the week name. (eg. Sun)

getDateSuffix([language])

Gets the date suffix for the day of the month. (eg. th)

getLastDate()

Gets the last day of the month. (eg. 31)

getLocale()

Gets the locale for the month and day names. The default is "en".

setLocale(locale)

Sets the locale for the month and day names.

format(format_string)

Gets a string representation of the date object based on the format_string. (eg. "DDDD, MMMM DS h:mm TT" = Wednesday, January 1st 12:00 AM)

Demo

Options

Try it







Comments