Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > GMT equivalent of mktime

Reply
Thread Tools

GMT equivalent of mktime

 
 
Rajmohan
Guest
Posts: n/a
 
      07-14-2003
Hi All,

I need help with date and time conversions. gmtime() gives struct tm and
localtime() gives the same with local correction. Is there a GMT equivalen
of mktime() also? Here is my sample program.

***********************
time_t now, NOW;
struct tm *today;

time(&now);
printf ("now: %d\n", now);

today = localtime(&now);

NOW = mktime (today);

printf ("NOW: %d\n", NOW);
*************************
And the Output is:
now: 1058194848
NOW: 1058194848

Now if i use gmtime() instead of localtime(), the output is:
now: 1058194815
NOW: 1058175015

The time_t value is not the same. If i want to use gmtime(), then is there a
GMT equivalent api for mktime? Why is this disparity in values?

thanks in advance,


 
Reply With Quote
 
 
 
 
Mark McIntyre
Guest
Posts: n/a
 
      07-14-2003
On Mon, 14 Jul 2003 20:54:20 +0530, in comp.lang.c , "Rajmohan"
<(E-Mail Removed)> wrote:

>Hi All,
>
>I need help with date and time conversions.


>***********************
>time_t now, NOW;


aside: not a good idea to have variables whose names differ only in
case. Also not a good idea to use ALL CAPS for a variable -
traditionally in C they're reserved for constants.

>NOW = mktime (today);
>And the Output is:
>now: 1058194848
>NOW: 1058194848
>
>Now if i use gmtime() instead of localtime(), the output is:
>now: 1058194815
>NOW: 1058175015


But the two times are different, one is 11pm and the other 10pm, or
whatever, so you'd expect them to have different time_t values.

In any events, as far as I'm aware, the precise handling of local time
conversions is implementation defined. Therefore you should use
consistent conventions. Either stick to GMT or stick to local time,
don't switch between them during your conversions or you will get
confused.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
time.mktime problem McBooCzech Python 4 09-05-2005 09:35 AM
mktime segfault Florian Quetting C++ 2 12-31-2004 05:45 PM
Time problem....mktime(), gmtime(), localtime() KW C Programming 1 12-08-2004 03:20 PM
time.mktime memory access violation bug Bengt Richter Python 6 11-21-2003 03:07 AM
mktime and DST. Gore C Programming 1 10-07-2003 09:29 AM



Advertisments