473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

GMT equivalent of mktime

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,
Nov 13 '05 #1
1 7343
On Mon, 14 Jul 2003 20:54:20 +0530, in comp.lang.c , "Rajmohan"
<ra*******@yahoo.com> 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 =---
Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: adam | last post by:
Hi all, I am having a problem with calculating a date. What I am looking to do is get the date of Sunday of this week, then use mktime() to find out other days in the past by subtracting days. ...
9
by: WebM¤nkey | last post by:
Hi folks Just found that the mktime function returns a negative value when the date is 26 march 2006 with 0 hours, 0 seconds and 0 minutes. Is this a documented problem ? Any suggestions ?
2
by: Bengt Richter | last post by:
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.mktime((1969, 12, 31, 17, 0, 0, 0, 0, 0))...
2
by: Florian Quetting | last post by:
Hi, I'm getting mad with following problem: The code compiles, but I always get a segfault and I don't have any clue why. I can't see any differences in my way of calling mktime and others. ...
4
by: McBooCzech | last post by:
Hi, on Linux (Fedora FC4) and Python 2.4.1 I am trying to know the time delta in seconds between two times given in the HHMMSS format. My code looks like: import datetime, time...
16
by: John Hanley | last post by:
I created a function that breaks down a date into broken down time, I subtract a certain number of seconds from that, then use mktime() to recompute the calendar time. It works basically except...
2
by: John Hanley | last post by:
I am getting some inconsistencies with mktime(). I allocate memory for my struct tm early in my program, and assign only *some* of the member variables. t->tm_sec=s; t->tm_min=m;...
9
by: Aditi | last post by:
I am working around a problem called Y2038 bug....
5
by: Robert Latest | last post by:
Here's what happens on my Windows machine (Win XP / Cygwin) at work. I've googled a bit about this problem but only found references to instances where people referred to dates before the Epoch. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.