GMT equivalent of mktime

Discussion in 'C Programming' started by Rajmohan, Jul 14, 2003.

  1. Rajmohan

    Rajmohan Guest

    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,
     
    Rajmohan, Jul 14, 2003
    #1
    1. Advertising

  2. On Mon, 14 Jul 2003 20:54:20 +0530, in comp.lang.c , "Rajmohan"
    <> 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 =---
     
    Mark McIntyre, Jul 14, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Florian Quetting

    mktime segfault

    Florian Quetting, Dec 31, 2004, in forum: C++
    Replies:
    2
    Views:
    534
    Florian Quetting
    Dec 31, 2004
  2. Gore

    mktime and DST.

    Gore, Oct 7, 2003, in forum: C Programming
    Replies:
    1
    Views:
    4,362
    Richard Bos
    Oct 7, 2003
  3. Bengt Richter

    time.mktime memory access violation bug

    Bengt Richter, Nov 18, 2003, in forum: Python
    Replies:
    6
    Views:
    744
    Bengt Richter
    Nov 21, 2003
  4. McBooCzech

    time.mktime problem

    McBooCzech, Aug 30, 2005, in forum: Python
    Replies:
    4
    Views:
    903
    Edvard Majakari
    Sep 5, 2005
  5. KW
    Replies:
    1
    Views:
    1,876
    Eric Sosman
    Dec 8, 2004
Loading...

Share This Page