473,408 Members | 1,826 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,408 software developers and data experts.

hellp about local timestamp

hello everyone:

How can I get local timestamp use c++/c, I only know is time(), but
time() returns a UTC timestamp, I want get local timestamp, how can
I do, I am under windows system.

thanks.

Zhaohui
Dec 7 '05 #1
3 12552
* Zhaohui:
hello everyone:

How can I get local timestamp use c++/c, I only know is time(), but
time() returns a UTC timestamp, I want get local timestamp, how can
I do, I am under windows system.


I would check the documentation.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 7 '05 #2
Its a bit off topic here, but look at localtime_r at POSIX/BSD systems.

Dec 7 '05 #3
Hi,
Have a look at this program which may help you.
I tried to print the time.

Thanks & Regds,
T.Mohanta

cat time.c

#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

void print_time ()
{
struct timeval tv;
struct tm* ptm;
char time_string[40];
long milliseconds;
double sec;
double secs;

/* Obtain the time of day, and convert it to a tm struct.
*/
gettimeofday (&tv, NULL);
ptm = localtime (&tv.tv_sec);
/* Format the date and time, down to a single second. */
strftime (time_string, sizeof (time_string), "%Y-%m-%d
%H:%M:%S",
ptm);
/* Compute milliseconds from microseconds. */
milliseconds = tv.tv_usec / 1000;
sec = tv.tv_sec;
/* Print the formatted time, in seconds, followed by a
decimal
point
* and the milliseconds. */

printf ("The sec--- value %d\n", sec);
printf ("%s\n", time_string);
printf ("The sec value %d\n", ptm->tm_sec);
printf ("%s.%03ld\n", time_string, milliseconds);
printf ("The min value ======%d\n", ptm->tm_min);
//printf ("%s.%03ld\n", time_string, milliseconds);
printf ("%d\n", time_string, milliseconds);
sleep(2);
gettimeofday (&tv, NULL);
secs = tv.tv_sec;
ptm = localtime (&tv.tv_sec);
/* Format the date and time, down to a single second. */
strftime (time_string, sizeof (time_string), "%Y-%m-%d
%H:%M:%S",
ptm);
milliseconds = tv.tv_usec / 1000;
printf ("%s.%03ld\n", time_string, milliseconds);
printf ("The sec--- value %d\n", secs);
printf ("The sec value %d\n", ptm->tm_sec);
printf ("The min value %d\n", ptm->tm_min);
printf ("The diff value %d\n", (secs-sec));
}
int main ()
{
print_time();
return 0;
}

Dec 7 '05 #4

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

Similar topics

2
by: Ben | last post by:
I would like to use php to query a database and retrieve a unix timestamp. The problem is that mysql is storing the data in the date format and not a timestamp. I am sure that I can amend my...
4
by: Dave | last post by:
The following function is called repeatedly from a stored proc. CREATE FUNCTION GetTaxRate ( v_AsOfDate TIMESTAMP, v_FilingStatusId INT) RETURNS DOUBLE BEGIN ATOMIC DECLARE v_retVal DOUBLE;...
6
by: Robert Schuldenfrei | last post by:
Dear NG, As expected, when I went to implement TIMESTAMP, I failed. With the help of Kevin Yu, I got the 2 code segments at the bottom working using a WHERE clause that checks all columns. ...
8
by: Super Mango | last post by:
Hi everubody, I have a timestamp field in a mysql DB and I want to know how much time has past since that timestamp. is it possible? Say that I have this value in a variable - 1) how do I...
10
by: manochavishal | last post by:
HI, I read that every char in expression is promoted to int. So as function arguments are expressions so type promotion should take place for arguments passed to function. so ***** int...
5
by: Simen Haugen | last post by:
Hi. How can I convert a python datetime to a timestamp? It's easy to convert a timestamp to datetime (datetime.datetime.fromtimestamp(), but the other way around...?) -Simen
0
by: bughunter | last post by:
Local server C:\TRACE>db2level DB21085I Instance "DB2" uses "32" bits and DB2 code release "SQL08024" with level identifier "03050106". Informational tokens are "DB2 v8.1.11.973", "s060120",...
2
by: James | last post by:
I am attempting to write a statement for inserting a current timestamp into a MySQL database. The MySQL field is of type datetime. The statement I first tried to generate a value for the field...
4
by: =?Utf-8?B?QnJhc3NpY2FOaWdyYQ==?= | last post by:
I have an application that uses CDO to send an email alert to management when certain events occur. The messages alway have the wrong time. It appears the time is UTC. The computer date and time...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.