strptime() equivalent on Windows?

Is there a good equivalent implementation of strptime() available for Windows? Unfortunately, this POSIX function does not appear to be available.

Open Group description of strptime - summary: it converts a text string such as "MM-DD-YYYY HH:MM:SS" into a tm struct, the opposite of strftime().

Answers


An open-source version (BSD license) of strptime() can be found here: http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/time/strptime.c?rev=HEAD

You'll need to add the following declaration to use it:

char *strptime(const char * __restrict, const char * __restrict, struct tm * __restrict);

If you don't want to port any code or condemn your project to boost, you can do this:

  1. parse the date using sscanf
  2. then copy the integers into a struct tm (subtract 1 from month and 1900 from year -- months are 0-11 and years start in 1900)
  3. finally, use mktime to get a UTC epoch integer

Just remember to set the isdst member of the struct tm to -1, or else you'll have daylight savings issues.


Need Your Help

Possible BUG in Android ImageDownloader class : sHardBitmapCache NOT static when it should be?

java android performance caching dalvik

I have been trying to learn as much as possible about Android development with specific focus on performance since many apps in the Play store today are sluggish. I have found/been directed to many

Air As3 XML editing/saving

xml actionscript-3 air editing save

I need to make a class that simplifies saving dynamic/input TextField text to an XML file. I've got it saving the XML object from as3 to a file on the file system without problems. Basically what I...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.