strftime

Solaris timezone in C (missing %z on strftime)

I have an application that writes to another application and needs to provide the date + timezone of the system. I have been using strftime with the %z argument to get the timezone, and it has been working very well on Linux. However, last week we decided to merge it to solaris just to find out that %z is not present. Someone suggested...

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 i = 0; i < 100000; i++) { sprintf(buf, "%4d-%02d-%02d %02d:%02d:%02d", sysTime.wYear...

C - Improper Pointer/Integer Combination in strftime()

I'm getting the compiler error: (83) error: improper pointer/integer combination: arg #1. Here's the code that is doing it: char boot_time[BUFSIZ]; ... Line 83: strftime(boot_time, sizeof(boot_time), "%b %e %H:%M", localtime(table[0].time)); where table is a struct and time is a time_t member. I read that "improper pointer/integ...

How do I format a date in ruby to include "rd" as in "3rd"

I want to format a date object so that I can display strings such as "3rd July" or "1st October". I can't find an option in Date.strftime to generate the "rd" and "st". Any one know how to do this? ...

str_to_date for ruby on rails?

so I have to insert a bunch of records from a data source that has dates in the format Sun, Sep 13 1:00 PM. I'm just going to execute SQL that uses STR_TO_DATE But I was wondering in case I need it in the future if you guys know of a way to do this using a ruby method...like a reverse strftime ...

Making Django forms.DateField show use local date format

I'm trying to find an easy way to build forms which show dates in the Australian format (dd/mm/yyyy). This was the only way I could find to do it. It seems like there should be a better solution. Things to note: Created a new widget which renders date value in dd/mm/yyyy format Created new date field to prepend the locate date for...

What is the cleanest way to remove beginning "0"'s from default dates in Ruby / Rails?

In /initializers/time_formats.rb I have this: Time::DATE_FORMATS[:profile] = "%m / %d / %Y" However this obviously produces dates such as: 09 / 08 / 2001 Google tells me my best bet is to use some kind of gsub regular expression to edit out the 0's. Is this true or is there a better alternative? ...

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 to find anything on displaying '-0500' at the end. Plus I'm getting the seconds as an int. ...

Is there any way to use a strftime-like function for dates before 1900 in Python?

I didn't realize this, but apparently Python's strftime function doesn't support dates before 1900: >>> from datetime import datetime >>> d = datetime(1899, 1, 1) >>> d.strftime('%Y-%m-%d') Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: year=1899 is before 1900; the datetime strftime() methods requi...

How to put a date from strftime in a nsstring in obj-c?

i want to be get a date (the current hour) from strftime and get it into a nsstring in obj-c for the iphone-os ...

format text_field helper?

Is it possible to apply strftime formatting to the value of a text input field using a Rails text_field helper? In the form I use for creating or editing a record, I have a text input field which is populated by a variant of the calendardateselect javascript. I click the text field and a little calendar pops up. After I select year, mont...

Unicode setlocale and strftime fails at windows

I have one page and it's encoding is UTF-8 and If i try to run that code in unix system everythings looks fine but when i try to run in windows(7) some chracters looks question mark(�). How can run the code fine both of two system(without using iconv). header('Content-Type: text/html; charset=UTF-8'); setlocale(LC_ALL, 'turkish'); echo ...

Coverting a string to a formatted date-time string using Python

I'm trying to convert a string "20091229050936" into "05:09 29 December 2009 (UTC)" >>>import time >>>s = time.strptime("20091229050936", "%Y%m%d%H%M%S") >>>print s.strftime('%H:%M %d %B %Y (UTC)') gives AttributeError: 'time.struct_time' object has no attribute 'strftime' clearly, I've made a mistake: time is wrong, it's a datetime ...

Safely calling strftime with untrusted format string

We have a C++/MFC application which allows users to customize date formatting via configuration files. Not wanting to reinvent the wheel, I pass the format string to CTime::Format("< format string >") to do the actual formatting. Under the covers, Format calls a variant of the standard C function strftime(). Naturally, the user can ac...

Iphone: How to read return value of strftime SQLite function

I need to read the column value of the following query SELECT strtime('%Y-%m', created_at) as field FROM table GROUP BY field the type of column field is 3 (I assume it is blog), but I need string How should I? Updated const char* sql = "SELECT CAST(strftime('%Y', created_at) as INTEGER) as year FROM table GROUP BY year i...

zsh: strftime command not found

I am currently learning the zsh and now I wanted to use strftime but i get: zsh: command not found: strftime I think I'm doin' something wrong, since I see people using that function all the time in their dotfiles. ...

C# Finisar SQLite DateTime Comparison Problem

My "task" database table look like this: [title] [content] [start_date] [end_date] [...] [...] [01.06.2010 20:10:36] [06.06.2010 20:10:36] [...] [...] [05.06.2010 20:10:36] [06.06.2010 20:10:36] And I want to find only those records that meet the condition that a given day is between start_date and end_date. I've tried the following ...

Using SQLite3 on iPhone to get midnight (this morning) as a UNIX timestamp

Okay, I really know this has GOT to be the long way around doing this... however, what I want is relatively simple one would think. I have a database with a timestamp column. I am using iPhone SDK with SQLite3. I want to have SQLite3 get all records for today (where timestamp >= midnight this morning) .. What i have come up with (th...

Is strftime with nanoseconds possible in bash?

Is there any way to obtain Unix Time with nanoseconds with strftime in bash? My line for unix time : <command> | awk '{ print strftime("%s"), $0; }' I cannot use date +%N because date is only evaluated once. Is there any work around? ...

How to update DATETIME field with existing data from same table

I have an sqlite database which currently holds an integer field called Year which currently only stores the year. In future versions I want to store a full date and time. I updated my table to include a FullDate field using alter table. > ALTER TABLE Files ADD COLUMN UploadDate DATETIME DEFAULT 0; Next, I want to migrate all the ex...