0

I found a solution for Windows:

istringstream ss_finish("2014-March-02 01:00:00");
ss_finish >> get_time(&t, "%Y-%b-%d %H:%M:%S");
time_t finish = mktime(&t);

But this is not compilable under Linux with gcc because get_time is not yet implemented (gcc 4.9)

I also found a solution for Linux based on strptime but this is not compilable under Windows because strptime is not recognized by the VS compiler.

Is there a cross-platform way to achieve this task?

I could do some #defines and check for the OS but maybe there are some other functions. And I wouldn't like to use boost's date-time functions.

Niall
  • 30,036
  • 10
  • 99
  • 142
remus
  • 2,635
  • 2
  • 21
  • 46
  • possible duplicate of [Convert a string to a date in C++](http://stackoverflow.com/questions/308390/convert-a-string-to-a-date-in-c) – sashoalm Oct 06 '14 at 09:08
  • The above code does compile if you use libc++ (ships with clang) rather than the gnu libstdc++. – Richard Hodges Oct 06 '14 at 09:28

2 Answers2

1
  1. Convert a string to a date in C++
  2. resenting boost (and doing so for a very specific and well implemented task) == reinventing the wheel
Community
  • 1
  • 1
pdeschain
  • 1,411
  • 12
  • 21
  • That is not an answer, it should have been an 'exact duplicate' flag, or a comment indicating as much. – sashoalm Oct 06 '14 at 09:08
1

Use <ctime>

You might want to check this out: updated link

galdin
  • 12,411
  • 7
  • 56
  • 71