Questions tagged [date-formatting]

Date formatting is the process of displaying, handling or converting a calendar date to a specific format.

Wikipedia goes into good detail about various date formats in its Date format by country article:

Basic components of a calendar date for the most common calendar systems:

Y – Year
M – Month
D – Day

Order of the basic components:

B – Big-endian (year, month, day), e.g. 1996-04-22
L – Little-endian (day, month, year), e.g. 22.04.96 or 22/04/96
M – Middle-endian (month, day, year), e.g. 04/22/96

Specific formats for the basic components

yyyy – Four-digit year, e.g. 1996
yy – Two-digit year, e.g. 96
mm – Two-digit month, e.g. 04
m – one-digit month for months below 10, e.g. 4
mmm – three-letter abbreviation for month
mmmm – month spelled out in full
dd – two-digit day, e.g. 02
d – one-digit day for days below 10, e.g. 2

Separators of the components

"/" – Slash
"." – Dots or full stops
"-" – Hyphens or dashes
" " – Spaces
1459 questions
2671
votes
58 answers

How to format a JavaScript date?

In JavaScript, how can I format a date object to print as 10-Aug-2010?
leora
  • 163,579
  • 332
  • 834
  • 1,328
2570
votes
56 answers

How do I get the current date in JavaScript?

How do I get the current date in JavaScript?
Suresh
  • 33,939
  • 15
  • 55
  • 62
458
votes
49 answers

Get String in YYYYMMDD format from JS date object?

I'm trying to use JS to turn a date object into a string in YYYYMMDD format. Is there an easier way than concatenating Date.getYear(), Date.getMonth(), and Date.getDay()?
IVR Avenger
  • 13,266
  • 12
  • 42
  • 55
249
votes
28 answers

How to format time since xxx e.g. “4 minutes ago” similar to Stack Exchange sites

The question is how to format a JavaScript Date as a string stating the time elapsed similar to the way you see times displayed on Stack Overflow. e.g. 1 minute ago 1 hour ago 1 day ago 1 month ago 1 year ago
Sky Sanders
  • 33,086
  • 5
  • 65
  • 88
240
votes
8 answers

How do I format a date as ISO 8601 in moment.js?

This docs mention moment.ISO_8601 as a formatting option (from 2.7.0 - http://momentjs.com/docs/#/parsing/special-formats/), but neither of these work (even 2.7.0): var date = moment(); date.format(moment.ISO_8601); // error moment.format(date,…
sennett
  • 6,676
  • 5
  • 39
  • 64
224
votes
10 answers

Convert timestamp to date in MySQL query

I want to convert a timestamp in MySQL to a date. I would like to format the user.registration field into the text file as a yyyy-mm-dd. Here is my SQL: $sql = requestSQL("SELECT user.email, info.name, …
remyremy
  • 2,818
  • 3
  • 26
  • 44
185
votes
21 answers

How to format a duration in java? (e.g format H:MM:SS)

I'd like to format a duration in seconds using a pattern like H:MM:SS. The current utilities in java are designed to format a time but not a duration.
kofte
139
votes
6 answers

Is there a date format to display the day of the week in java?

I know of date formats such as "yyyy-mm-dd" -which displays date in format 2011-02-26 "yyyy-MMM-dd"-which displays date in format 2011-FEB-26 to be used in eg: SimpleDateFormat formatter = new SimpleDateFormat( "yyyy/MMM/dd "); I…
rogerstone
  • 6,881
  • 11
  • 49
  • 60
132
votes
8 answers

Formatting NSDate into particular styles for both year, month, day, and hour, minute, seconds

I basically need to get current date and time separately, formatted as: 2009-04-26 11:06:54 The code below, from another question on the same topic, generates now: |2009-06-01 23:18:23 +0100| dateString: |Jun 01, 2009 23:18| parsed: …
bcsantos
  • 2,615
  • 5
  • 19
  • 21
124
votes
11 answers

How to ISO 8601 format a Date with Timezone Offset in JavaScript?

Goal: Find the local time and UTC time offset then construct the URL in following format. Example URL: /Actions/Sleep?duration=2002-10-10T12:00:00−05:00 The format is based on the W3C recommendation: http://www.w3.org/TR/xmlschema11-2/#dateTime The…
Meow
  • 16,125
  • 50
  • 122
  • 176
98
votes
5 answers

What are the "standard unambiguous date" formats for string-to-date conversion in R?

Please consider the following $ R --vanilla > as.Date("01 Jan 2000") Error in charToDate(x) : character string is not in a standard unambiguous format But that date clearly is in a standard unambiguous format. Why the error message? Worse, an…
Matt Dowle
  • 56,107
  • 20
  • 160
  • 217
68
votes
12 answers

Oracle's default date format is YYYY-MM-DD, WHY?

Oracle's default date format is YYYY-MM-DD. Which means if I do: select some_date from some_table ...I lose the time portion of my date. Yes, I know you can "fix" this with: alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'; But…
Aaron Fi
  • 9,410
  • 13
  • 61
  • 90
65
votes
7 answers

Date formatting in WPF datagrid

I want to change is the date column from a format "DD/MM/YYYY HH:MM:SS" to "DD.MM.YYYY".
Harald
  • 731
  • 3
  • 10
  • 15
62
votes
3 answers

Format Date output in JSF

If #{myBean.birthdate} is of java.util.Calendar or java.util.Date type, can I possibly format this inside the EL itself using an existing function perhaps, with the output of like the one produced by the DateFormat's SHORT, MEDIUM,LONG abd FULL…
Albert Gan
  • 16,262
  • 44
  • 125
  • 177
57
votes
3 answers

How to specify date format when using pandas.to_csv?

The default output format of to_csv() is: 12/14/2012 12:00:00 AM I cannot figure out how to output only the date part with specific format: 20121214 or date and time in two separate columns in the csv file: 20121214, 084530 The documentation is…
user1642513
1
2 3
97 98