My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
DateFormatting  
Date formatting commands.
Updated Sep 13, 2010 by gars...@gmail.com

Introduction

The dateformat plugin for jQuery adds the ability to use a string of placeholder characters to describe the format which should be used to print a date.

Usage

var date = new Date();
$('#date').text(date.format('F j, Y')); // May 18, 2010
alert($.dateformat.format('F j, Y', date));   // May 18, 2010

Formatting Rules

Character Description Example
Timer Formatting* -- --
V Number of days since epoch 1 to Infinity
v Number of days since epoch, padded to two digits 01 to Infinity
K Number of days since epoch, offset for years 1 to 364
k Number of days since epoch, offset for years, padded to two digits 01 to 364
X Number of hours since epoch 0 to 23
x Number of hours since epoch, padded to two digits 00 to 23
p Number of minutes since epoch 0 to 59
C Number of minutes since epoch, padded to two digits 00 to 59
E Number of minutes since the epoch, uncapped by hours 0 to Infinity
e Number of minutes since the epoch, uncapped by hours, padded to two digits 00 to Infinity
Day Formatting -- --
d Day of the month, padded to two digits 01 to 31
D Textual representation of the day of the week, three letters Mon through Sun
j Day of the month without leading zeros. 1 to 31
l Full textual representation of the day of the week Monday through Sunday
N ISO-8601 numeric representation of the day of the week. 1 (for Monday) through 7 (for Sunday)
S English ordinal suffix for the day of the month, two characters st, nd, rd, th
w Numeric representation of the day of the week 0 (for Monday) through 6 (for Sunday)
z The day of the year, starting from 0. 0 through 365
Week Formatting -- --
W ISO-8601 week number of year, weeks starting on Monday Ex: 42 (42nd week in the year)
Month Formatting -- --
F A full textual representation of a month. January through December
m Numeric representation of a month, padded to two digits. 01 to 12
M Short textual representation of a month, three letters. Jan to Dec
n Numeric representation of a month, without leading zeros. 1 to 12
t Number of days in the given month. 28 to 31
Year Formatting -- --
L Whether it's a leap year. 1 if it is a leap year, 0 otherwise. 1 or 0
f Date object of the first day of the current year Date
Y A full numeric representation of the year, 4 digits 2004
y A two digit representation of the year. 04
Time Formatting -- --
a Lowercase Ante/Post Meridiem values. am or pm
A Uppercase Ante/Post Meridiem values. AM or PM
B Swatch Internet Time** 000 to 999
g 12-hour format of an hour. 1 to 12
G 24-hour format of an hour. 0 to 23
h 12-hour format of an hour, padded to two digits. 01 to 12
H 24-hour format of an hour, padded to two digits. 00 to 23
i Minutes, padded to two digits. 00 to 59
s Seconds, padded to two digits. 00 to 59
u Microseconds Ex. 654321
Timezone Formatting -- --
O Difference to GMT in hours Ex: +0200
P Difference to GMT in hours, with color between minutes and hours Ex: +02:00
Z Timezone offset in seconds Ex: -43200 through 50400
Full Date/Time Formatting -- --
c ISO 8601 date 2004-02-12T15:19:21+00:00
r FC 2822 formatted date Ex: Thu, 21 Dec 2000 16:01:07 +0200
U The number of seconds since the epoch. Ex. 1262325600
Custom epiclock Formatting -- --
Q The display offset as years. Ex. 2
E The display offset as days. Ex. 6
e The display offset as days, padded to two digits. Ex. 06

* These rules are used for displaying timer information, working under the assumption that a timer is represented by subtracting the start time of the timer from the date the timer was started, thus offsetting the working date the the epoch, and counting the displacement as the seconds from that offset value.

** If you ever use this formatting method (Swatch internet time) drop an email to garside@gmail.com, as I'm not convinced any real people actually use this.

Comment by cristian...@gmail.com, Oct 23, 2011

How could I compare two dates? I'd like to use the stopwach mode in a game to show what is the fastest resolution of the game, and create a top ten.

Comment by vbesso...@gmail.com, Jan 28, 2013

how to use letters in format string (for example word 'days') without render it as format characters?

Powered by Google Project Hosting