473,802 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about ctime

Hi all,

anybody here can tell me what exactly is returned by the standard
function time() in <ctime> (or time.h). Please dont tell me it is the
number of seconds since 1 Jan of 1970 GMT, cos it is not (at least not
in my case!).

If I pass this number to a Java program (print it using a
java.util.Date( ) object), the result is the current date minus one
hour. If I generate the current number of seconds since 1970 in a Java
program and use it in a C++ program (print it using localtime and
asctime), the result is the current date plus one hour. I tested it
changing the time zone of my computer and the results were the same.

My conclusions are:
1. time() returns the number of seconds since 1 Jan 1970 GMT minus one
hour;
2. localtime() adjusts the date above to the correct localtime (sum
one hour) and store it in a structure.

Does anybody know if I am right? If yes, why was it implemented that
way?

Thanks in advance,
Tivo
Jul 19 '05 #1
1 4267
"Tivo Escobar" <ti**********@b ol.com.br> wrote...
anybody here can tell me what exactly is returned by the standard
function time() in <ctime> (or time.h). Please dont tell me it is the
number of seconds since 1 Jan of 1970 GMT, cos it is not (at least not
in my case!).
"The time function returns the implementation' s best approximation
to the current calendar time. The value (time_t)(-1) is returned
if the calendar time is not available."

That's how C Standard defines it. Take it or leave it.
If I pass this number to a Java program (print it using a
java.util.Date( ) object), the result is the current date minus one
hour.
Neither C Standard nor C++ Standard defines what's going to happen
when you pass that value anywhere but gmtime, ctime, or localtime
functions.
If I generate the current number of seconds since 1970 in a Java
program and use it in a C++ program (print it using localtime and
asctime), the result is the current date plus one hour. I tested it
changing the time zone of my computer and the results were the same.
This has really no relevance in comp.lang.c++, but thank you for
sharing your findings.

Just for the fun of it, is the Daylight Savings Time active on
your system?
My conclusions are:
1. time() returns the number of seconds since 1 Jan 1970 GMT minus one
hour;
Nope. It returns "the implementation' s best approximation of the
current calendar time" if one is available.
2. localtime() adjusts the date above to the correct localtime (sum
one hour) and store it in a structure.
localtime indeed takes a pointer to time_t value returned from (or
by) the time() function and converts it into 'tm' structure. Whether
it adjusts it or not is unspecified. Adjustment can be viewed as
part of the conversion.
Does anybody know if I am right?
Partially.
If yes, why was it implemented that
way?


Whatever way it was implemented, it's implementation detail. Why
it's done that way and not any other way, is a question to those
who implemented it.

Victor
Jul 19 '05 #2

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

Similar topics

3
2429
by: Kevin | last post by:
Hello: I am trying to find documentation on using the ctime library as I need to be able to instantiate an object to keep track of the time when a certain event occurs. I also need to be able to take two of those objects and perform calculations on them like: the time difference, summing them, getting the mean time between events, etc. Is ctime what I should be using? Is there a better way?
1
574
by: wukexin | last post by:
I write my own class Cfile, I want to know what about implement ctime().Who help me? My use function ctime, I sign it with $$$. my class Cfile: #------------------------ file.h #--------------------------- #include <io.h> #include <ctime> #include <string>
5
4661
by: berkay | last post by:
long num,num1; char *first; char *last; num=ilk.getTime();//gets time first=ctime(&num); cout.flush(); fflush(stdin); 1) cout<<"first:"<<first;
2
2958
by: Hao Xu | last post by:
Hi everyone! I think that everyone knows ctime() in glibc: The ctime(), gmtime() and localtime() functions all take an argument of data type time_t which represents calendar time. When interpreted as an absolute time value, it represents the number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC). Now I need to use the function of ctime() in linux kernel, but it
2
18875
by: Chris | last post by:
Hello, How can i convert a C++ CTime (4 bytes) into a C# DateTime ? (my CTime is read in a file). Thanks, -- Chris
6
1076
by: Schüle Daniel | last post by:
hello NG, consider this code >>> def timelogger(f): .... def wrapper(*a,**kw): .... print "started at %s" % time.ctime() .... t0 = time.time() .... f(*a, **kw) .... t1 = time.time()
4
9366
by: Gary Wessle | last post by:
Hi I am not getting current time with this program, what am I doing wrong? #include <ctime> #include <iostream> using namespace std; #define P(x) cout << #x " = " << (x) << "\n";
11
3551
by: aisling.cronin | last post by:
Hi I am using ctime to convert the following string 1144412677847 .... Please could some one to double check if they get the same result as me (The Time is Sun Nov 02 09:11:51 2031). It seems incorrect and would like a second opion. #include <time.h> #include <stdio.h>
4
3384
by: Pietro Cerutti | last post by:
Hi group, #include <stdio.h> #include <unistd.h> #include <time.h> int main(void) { time_t t1, t2; char *st1, *st2;
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10303
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10282
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10061
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.