date and time conversion to EPOCH seconds

R

Rajmohan

Hi All,

I can convert a current time in time_t form to user understandable form
using the apis - time, gmtime and strftime.

How can i convert in the reverse way? ie take a time and date string in the
form "Thu, 21 Feb 2002 13:02:03 GMT" and convert into time_t seconds? Is
there any c library api available for accomplishing this?

Thanks in advance,

regards,
Rajmohan
 
J

Jun Woong

Rajmohan said:
Hi All,

I can convert a current time in time_t form to user understandable form
using the apis - time, gmtime and strftime.

How can i convert in the reverse way? ie take a time and date string in the
form "Thu, 21 Feb 2002 13:02:03 GMT" and convert into time_t seconds? Is
there any c library api available for accomplishing this?

You can convert the tm structure to the time_t value by using
mktime(); you can also do the time arithmetic with it. But there is
no standard function to convert a string to the time_t value or the
tm structure; some implementations provide a non-portable function for
that purpose as an extension. Use it if any, or make yours if none or
it doesn't taste to yours.
 
M

Mark McIntyre

Richard,

Thanks a lot. But none of the routines - strptime/partime/getdate are
available on Win32 platform. Could u please point to links for win32...

simplest way with a format like that would be to parse it yourself
into a struct tm. Should take about 30 mins to write the code, faster
than searching the web.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top