You are here:

C/I am trying to find a simple program to convert a time to epoch time.

Advertisement


Question
-------------------------
Followup To
Question -
I am trying to find a program that converts a date and time to Unix epoch time (I am using a solaris system).  For instance,
Thu, 20 May 2004 00:27:15 needs to be converted to epochtime.  I know it is not a real hard program but I cannot program in C.

I would really appreciate it if you could help me.

Rachel Alexander
Answer -
I think the function mktime() is what you are looking for.
It is there in Linux. Check if it is in Solaris also?

-ssnkumar

mktime is indeed a function in solaris.  But seeing as I can't program in C I don't know what kind of structure to give my program.

Rachel

Answer
Read the man page.
Here is the structure used by it:
struct tm {
        int     tm_sec;         /* seconds */
        int     tm_min;         /* minutes */
        int     tm_hour;        /* hours */
        int     tm_mday;        /* day of the month */
        int     tm_mon;         /* month */
        int     tm_year;        /* year */
        int     tm_wday;        /* day of the week */
        int     tm_yday;        /* day in the year */
        int     tm_isdst;       /* daylight saving time */
};

-ssnkumar

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.