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

725 questions
12
votes
5 answers

strftime formatting with Ruby/Rails -- Lowercase am/pm

I have the following: @comment.created_at.strftime("%I:%M %p %b %d") Which outputs: 10:32 AM Dec 19 I'd like to output a lowercase am, like: 10:32am Dec 19 Any ideas on how to do that with ruby/rails? thanks
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
12
votes
1 answer

How can I print a date/time from time::strftime without leading zeros?

How can I print a date/time without leading zeros? For example, Jul 5, 9:15. According to the docs it uses the same syntax as strftime, however suppressing leading zeros time::strftime("%b %-d, %-I:%M", &time::now()).unwrap() leads to an…
Peter Uhnak
  • 9,617
  • 5
  • 38
  • 51
12
votes
1 answer

Datetime formatting in R3.0.3 and R3.1.3

I have a package on CRAN called UNF, which creates a hash of a data.frame (for use in data citation). I have some tests in the package related to the formatting of datetimes (I'm using testthat). They work correctly on the current version of R…
Thomas
  • 43,637
  • 12
  • 109
  • 140
11
votes
3 answers

Using strftime function in mawk

I'm trying to create AWK script that will filter the input file according to some pattern, and use the strftime() function for some calculations. ($2 ~ /^[HB]/ && $2 ~ /n$/){ print strftime("%Y") } The interpreter in use is mawk. When…
Ariel.T
  • 111
  • 1
  • 1
  • 3
11
votes
3 answers

SQLite return wrong week number for 2013?

I have a simple SQL for calculating week number in my reports on SQLite SELECT STRFTIME('%W', 'date_column') It was correct for 2009-2012. In 2013 I got always the wrong week number. For example SELECT STRFTIME('%W', '2012-02-28') return '09' and…
WebDucer
  • 1,114
  • 2
  • 16
  • 39
10
votes
4 answers

Swift: NSDate formatting with strftime & localtime

How do I convert the following Objective-C code into Swift code? #define MAX_SIZE 11 char buffer[MAX_SIZE]; time_t time = [[NSDate date] timeIntervalSince1970]; strftime(buffer, MAX_SIZE, "%-l:%M\u2008%p", localtime(&time)); NSString *dateString =…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
10
votes
2 answers

strptime defaulting to 1900

from datetime import datetime datetime.strptime('%b%d %I:%M%p', 'AUG21 3:26PM') results with 1900-08-21 15:26:00 how can I write in pythonic way so that when there's no year, take the current year as default (2013)? I checked and strftime…
eligro
  • 785
  • 3
  • 13
  • 23
10
votes
5 answers

Rails undefined method `strftime' for "2013-03-06":String

I am getting the error undefined method `strftime' for "2013-03-06":String when trying to display a date normally (June Sunday 3, 2013 or something similar) from the string 2013-03-06 using strftime. The line that does this in my index.html.erb and…
Colin
  • 491
  • 1
  • 5
  • 13
10
votes
7 answers

Spanish Characters not Displaying Correctly

I am getting the lovely � box where spanish characters should be displayed. (ie: ñ, á, etc). I have already made sure that my meta http-equiv is set to utf-8: I have also made…
NotJay
  • 3,919
  • 5
  • 38
  • 62
10
votes
1 answer

How to properly check strptime for valid dates in C

I'm doing the following to convert and check a date, however, I'm not sure why the following date keeps validating as true. Wouldn't %d check only for [01,31] + leading zeros? Is there a better and more accurate way of doing this? #include…
user1024718
  • 573
  • 6
  • 18
9
votes
1 answer

Are 'US/Eastern' and 'US/Central' and 'US/Pacific' deprecated for strftime or just PHP?

I have a shell script (zsh, to be precise) which uses strftime "%I:%M %p %Z (%a, %b %d)" "$EPOCHSECONDS" to generate a "current time" such as "02:45 PM CST (Thu, Mar 01)" This needs to be able to display the time in several different USA timezones,…
TJ Luoma
  • 301
  • 2
  • 7
9
votes
6 answers

python ISO 8601 date format

i'm trying to format the date like this, 2015-12-02T12:57:17+00:00 here's my code time.strftime("%Y-%m-%dT%H:%M:%S%z", time.gmtime()) which gives this result, 2015-12-02T12:57:17+0000 i can't see any other variations of %z that can provide the…
user3768071
  • 727
  • 5
  • 12
  • 17
9
votes
12 answers

How can I improve/replace sprintf, which I've measured to be a performance hotspot?

Through profiling I've discovered that the sprintf here takes a long time. Is there a better performing alternative that still handles the leading zeros in the y/m/d h/m/s fields? SYSTEMTIME sysTime; GetLocalTime( &sysTime ); char buf[80]; for (int…
Corey Trager
  • 22,649
  • 18
  • 83
  • 121
9
votes
1 answer

Convert strftime in SQLite request to MySQL

I converted the SQLite line WHERE strftime('%d%m', orders.created_at) = ....... directly to a MySQL monster: WHERE CONCAT(CAST(DAY(orders.created_at) AS CHAR), LPAD(CAST(MONTH(orders.created_at) AS CHAR), 2, '0')) = ......... Please, help me to…
Paul
  • 25,812
  • 38
  • 124
  • 247
9
votes
3 answers

Using strftime in C, how can I format time exactly like a Unix timestamp?

Here's the sort of time formatting I'm after: 2009-10-08 04:31:33.918700000 -0500 I'm currently using this: strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", ts); Which gives: 2009-10-11 13:42:57 CDT Which is close, but not exact. I can't seem…
Vlad the Impala
  • 15,572
  • 16
  • 81
  • 124
1 2
3
48 49