Questions tagged [strftime]

`strftime` is a C standard library function to format date and time into a readable form that has also been ported into other programming language standard libraries

strftime is a C standard library function to format date and time into a readable form that has also been ported into other programming language standard libraries

623 questions
1219
votes
14 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
  • 17,761
  • 11
  • 33
  • 42
925
votes
17 answers

Converting unix timestamp string to readable date

I have a string representing a unix timestamp (i.e. "1284101485") in Python, and I'd like to convert it to a readable date. When I use time.strftime, I get a TypeError: >>>import time >>>print time.strftime("%B %d %Y", "1284101485") Traceback (most…
VeryNewToPython
  • 9,283
  • 3
  • 13
  • 3
322
votes
18 answers

Python strftime - date without leading 0?

When using Python strftime, is there a way to remove the first 0 of the date if it's before the 10th, ie. so 01 is 1? Can't find a %thingy for that? Thanks!
Solihull
  • 5,299
  • 5
  • 20
  • 12
247
votes
8 answers

Convert python datetime to epoch with strftime

I have a time in UTC from which I want the number of seconds since epoch. I am using strftime to convert it to the number of seconds. Taking 1st April 2012 as an example. >>>datetime.datetime(2012,04,01,0,0).strftime('%s') '1333234800' 1st of April…
Noel
  • 3,132
  • 3
  • 18
  • 18
145
votes
8 answers

How to change the datetime format in pandas

My dataframe has a DOB column (example format 1/1/2016) which by default gets converted to pandas dtype 'object': DOB object Converting this to date format with df['DOB'] = pd.to_datetime(df['DOB']), the date gets converted to: 2016-01-26 and its…
yome
  • 1,905
  • 3
  • 14
  • 17
119
votes
8 answers

Using %f with strftime() in Python to get microseconds

I'm trying to use strftime() to microsecond precision, which seems possible using %f (as stated here). However when I try the following code: import time import strftime from time print strftime("%H:%M:%S.%f") ...I get the hour, the minutes and…
kolkko
  • 1,315
  • 2
  • 8
  • 6
116
votes
1 answer

What exactly does the T and Z mean in timestamp?

I have this timestamp value being return by a web service "2014-09-12T19:34:29Z" I know that it means timezone, but what exactly does it mean? And I am trying to mock this web service, so is there a way to generate this timestamp using strftime in…
roymustang86
  • 6,418
  • 19
  • 60
  • 96
89
votes
4 answers

Ruby strftime: Month without leading zero?

Does Ruby's strftime have a format for the month without a leading zero? I found %e for getting the day without the leading zero, but not having any luck with the month. Ultimately wanting a date formatted like: 9/1/2010
Shpigford
  • 22,682
  • 52
  • 149
  • 235
64
votes
3 answers

Rails: How to make Date strftime aware of the default locale?

I have my default locale set in the environment.rb as de (German). I also see all the error messages in German, so the locale is picked up by the server. But when I try to print date with strftime like following: some_date.strftime('%B, %y') It…
rangalo
  • 4,910
  • 8
  • 42
  • 65
37
votes
1 answer

C++11 alternative to localtime_r

C++ defines time formatting functions in terms of strftime, which requires a struct tm "broken-down time" record. However, the C and C++03 languages provide no thread-safe way to obtain such a record; there is just one master struct tm for the whole…
Potatoswatter
  • 126,977
  • 21
  • 238
  • 404
36
votes
3 answers

How do I strftime a date object in a different locale?

I have a date object in python and I need to generate a time stamp in the C locale for a legacy system, using the %a (weekday) and %b (month) codes. However I do not wish to change the application's locale, since other parts need to respect the…
MagerValp
  • 2,592
  • 1
  • 22
  • 27
35
votes
4 answers

Use datetime.strftime() on years before 1900? ("require year >= 1900")

I used : utctime = datetime.datetime(1601,1,1) + datetime.timedelta(microseconds = tup[5]) last_visit_time = "Last visit time:"+ utctime.strftime('%Y-%m-%d %H:%M:%S') But I have the time of 1601, so the error show: ValueError: year=1601 is before…
Alex
  • 839
  • 3
  • 11
  • 20
32
votes
5 answers

Display the date, like "May 5th", using pythons strftime?

Possible Duplicate: Python: Date Ordinal Output? In Python time.strftime can produce output like "Thursday May 05" easily enough, but I would like to generate a string like "Thursday May 5th" (notice the additional "th" on the date). What is the…
Buttons840
  • 8,107
  • 14
  • 50
  • 81
32
votes
3 answers

How to convert week number and year into unix timestamp?

I'm trying to group together dates into a week number and year, and then I want to convert that week number back into a unix timestamp. How can I go about doing this?
blacktie24
  • 4,697
  • 6
  • 37
  • 50
25
votes
2 answers

How do you set a strftime with javascript?

I need to custom format dates. In ruby, I would use strftime, or string formatted time, to accomplish this. now = Time.new now.strftime '%a, %d of %b' #=> "Sat, 27 of Jun" Does javascript use strftime or some equivalent? How can I get a similar…
williamcodes
  • 4,332
  • 7
  • 22
  • 43
1
2 3
41 42