Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

c++ - 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().

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...