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
1690 questions
3434
votes
69 answers

How do I format a date in JavaScript?

How do I format a Javascript Date object as a string? (Preferably in the format: 10-Aug-2010)
leora
  • 188,729
  • 360
  • 878
  • 1,366
2975
votes
61 answers

How do I get the current date in JavaScript?

How do I get the current date in JavaScript?
Suresh
  • 38,717
  • 16
  • 62
  • 66
1469
votes
18 answers

YYYY-MM-DD format date in shell script

I tried using $(date) in my bash shell script, however, I want the date in YYYY-MM-DD format. How do I get this?
Kapsh
  • 20,751
  • 13
  • 36
  • 44
538
votes
53 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
  • 15,090
  • 13
  • 46
  • 57
362
votes
41 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
  • 36,396
  • 8
  • 69
  • 90
306
votes
9 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
  • 8,014
  • 9
  • 46
  • 69
286
votes
13 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
  • 3,548
  • 3
  • 39
  • 56
225
votes
22 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
205
votes
22 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. The documentation says: For example,…
Meow
  • 18,371
  • 52
  • 136
  • 180
171
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
  • 7,541
  • 11
  • 53
  • 62
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,635
  • 5
  • 21
  • 22
113
votes
8 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
  • 58,872
  • 22
  • 166
  • 224
81
votes
5 answers

datetime to string with time zone

I have a DateTime stored in universal time (UTC) of value 2010-01-01 01:01:01. I would like to display it in EST in this format 2010-01-01 04:01:01GMT-04:00, however the 'K' formatter for timezone doesn't work in ToString
Comma
  • 1,567
  • 3
  • 15
  • 22
78
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
75
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
  • 849
  • 3
  • 11
  • 15
1
2 3
99 100