0

I'm parsing files with date and time in it. Let's say i have the date and time in the following format:

2009/07/18 10:48:39 CET (value in txt-file)

This is in ET:

2009/07/18 4:48:39 ET (could also be the value i parsed)

Is there a solution to convert between the times/dates? Maybe boost?

Couldn't find helpful infos in the boost docs.

Let's say i want to from CET to ET or ET to EST or CET to EST in c++, what would you do?

JSW189
  • 6,267
  • 11
  • 44
  • 72
extreme001
  • 303
  • 1
  • 5
  • 16

2 Answers2

0

strftime allows you to print out a struct tm* object using datetime formatting characters (%Y, %m, %d, etc).

What you could do is load a struct tm* object up by parsing your input data (assuming it's regular, this shouldn't require a lot of code), then modify the individual parts of the tm struct with some custom logic based on your timezone conversion (add hour, then check if you need to update day based on new hour value), then print this datetime value in the format you'd like via strftime. Not nearly as simple as the strptime/strftime functions available in php, but a solution nonetheless.

ryanbwork
  • 2,123
  • 12
  • 12
  • Thank you! But that's not really what i was looking for. I need a solution to convert between ET and CET or EST. Any idea if there's a lib that can do it? – extreme001 Dec 12 '12 at 18:13
  • looks like boost does support some datetime modifications, see http://www.boost.org/doc/libs/1_52_0/doc/html/date_time.html – ryanbwork Dec 12 '12 at 19:04
  • also, see this thread http://stackoverflow.com/questions/13846334/how-to-format-incomplete-dates-and-times-in-a-locale-specific-manner. I'd think boost would have a type of parse function so you don't have to load up the boost specific time struct by hand (like above), but I don't have experience with boost datetime. – ryanbwork Dec 12 '12 at 19:09
  • OK. Thank you i'l have a look at boost. I already overlooked boost and couldn't find any support for ET to EST or CET to ET and so on. Maybe the boost-users mailing list helps. Thank you! – extreme001 Dec 16 '12 at 11:55
0

I recommend https://github.com/google/cctz

Also note that "CET" and "ET" are not real time zone identifiers. They may be abbreviations for some time zone, but they do not uniquely identity an actual time zone. If you have some control over the data in the file, you should change "CET" and "ET" to numeric UTC offset values, such as those produced by %z from strftime() (and cctz::Format()). A numeric UTC offset and the Y/M/D H:M:S fields will let you correctly parse out the exact time instant.