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
55
votes
4 answers

Convert string to date in my iPhone app

I have made a calendar application for the iPhone in which I have a date in string format (e.g. "Tue, 25 May 2010 12:53:58 +0000"). I want to convert this to an NSDate. What do I need to use to do that?
AppAspect
  • 4,431
  • 2
  • 27
  • 46
55
votes
2 answers

Parse date in MySQL

How to convert the following into date for insertion/update into a TIMESTAMP or DATE field in MySQL? '15-Dec-09' DATE_FORMAT() is used to format date, but not the other way around.
user157195
47
votes
3 answers

`uuuu` versus `yyyy` in `DateTimeFormatter` formatting pattern codes in Java?

The DateTimeFormatter class documentation says about its formatting codes for the year: u year year 2004; 04 y year-of-era year 2004; 04 … Year: The count of letters…
Basil Bourque
  • 218,480
  • 72
  • 657
  • 915
43
votes
6 answers

Using DateFormatter on a Unix timestamp

I get a crash when running and it points at the dateFormmater.timezone. The error in the console is: Could not cast value of type 'Swift.Optional' (0x1192bf4a8) to 'NSTimeZone' (0x1192c0270). the value of rowEvents.date is "1480134638.0" Im…
CRey
  • 1,020
  • 2
  • 9
  • 21
41
votes
6 answers

How to insert date values into table

How can I insert into table with different input using / ,with date datatype? insert into run(id,name,dob)values(&id,'&name',[what should I write here?]); I'm using oracle 10g.
AbIr Chanda
  • 519
  • 1
  • 4
  • 3
40
votes
3 answers

In the Django admin site, how do I change the display format of time fields?

I recently added a new model to my site, and I'm using an admin.py file to specify exactly how I want it to appear in the admin site. It works great, but I can't figure out how to get one of my date fields to include seconds in it's display format.…
Trindaz
  • 14,751
  • 20
  • 74
  • 103
40
votes
4 answers

Time ISO 8601 in Ruby

I am trying to return a date with this format 2015-10-07T00:32:50.877+0000 I have tested that Time.now.iso8601 => "2015-10-21T09:47:50-04:00" but i didn't have same format tks
Bolo
  • 2,168
  • 4
  • 24
  • 31
37
votes
6 answers

Java Convert GMT/UTC to Local time doesn't work as expected

In Order to show a reproducible scenario, I am doing the following Get the current system time (local time) Convert Local time to UTC // Works Fine Till here Reverse the UTC time, back to local time. Followed 3 different approaches (listed below)…
35
votes
6 answers

How to convert date in to yyyy-MM-dd Format?

Sat Dec 01 00:00:00 GMT 2012 I have to convert above date into below format 2012-12-01 How can i? i have tried with following method but its not working public Date ConvertDate(Date date){ DateFormat df = new…
User 1531343
  • 8,084
  • 12
  • 86
  • 158
33
votes
2 answers

sqlite timestamp formatting

I am trying to work with dates in an sqlite database. I am storing my dates as timestamps, but when I use strftime() to format them to human readable dates I am getting back unxpected results. Consider the following, I select the current…
Kevin Bradshaw
  • 6,122
  • 11
  • 45
  • 73
33
votes
7 answers

Convert a time span in seconds to formatted time in shell

I have a variable of $i which is seconds in a shell script, and I am trying to convert it to 24 HOUR HH:MM:SS. Is this possible in shell?
Darren
  • 9,190
  • 7
  • 38
  • 58
29
votes
2 answers

ORA-01810: format code appears twice

Why is the sql below generating an ORA-01810 error? I researched the error and I am using different date formats for each date insert INSERT INTO bag_grte_clm ( schd_dprt_ldt, arr_trpn_stn_cd, bkg_crtn_gdt, sbmt_bag_grte_clm_dt, …
LedMan1001
  • 309
  • 1
  • 3
  • 4
29
votes
7 answers

Formatting date to human readable format

Lets say in my mysql database I have a timestamp 2013-09-30 01:16:06 and lets say this variable is $ts. How can I output this to show more like September 30th, 2013?
soniccool
  • 4,688
  • 19
  • 54
  • 89
26
votes
4 answers

PHP Fatal error: Call to a member function format() on boolean

Crashes on: format('Y-m-d h:i:s'); ?> PHP Fatal error: Call to a member function format() on boolean But with other dates works well:
user1539207
  • 263
  • 1
  • 3
  • 7
24
votes
5 answers

Displaying the last two digits of the current year in Java

How can I display only the last two digits of the current year without using any substring algorithms or any third party libraries? I have tried the below method and it gave a four-digit year. I want to know whether there are any date formatting…
нαƒєєz
  • 1,119
  • 4
  • 13
  • 27
1
2
3
97 98