473,324 Members | 2,179 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.

Time conversion in C

This is all in C:

I have 2 time values:

System time and an input from the user.

1) System time is in the form of seconds from 1/1/1970 calculated by
using

time_t secs;
SYSTEMTIME stime;

time(&secs);

2) The input from the user is in form hr:min:sec which is a string
value.

But the seperate values have been obtained by using

sscanf(storedTimeValue, "%d:%d:%d", &hour,&minutes,&seconds);

So now I have 3 integer values for hour,minutes and seconds.

3) I have a function which calculates the time difference between 2
time values,
but both these time values need to be seconds from 1/1/1970.

Is there any way by which,I could convert the user given time into time
in seconds from 1/1/1970,
so that I can get the difference between the system time and the user
given time.

Nov 6 '06 #1
3 4267
moni <mo*******@gmail.comwrote:
This is all in C:
<snip>

Do you have a question relating to C#?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 6 '06 #2
moni wrote:
This is all in C:
So why ask in a C# group ?
I have 2 time values:

System time and an input from the user.

1) System time is in the form of seconds from 1/1/1970 calculated by
using

time_t secs;
SYSTEMTIME stime;

time(&secs);

2) The input from the user is in form hr:min:sec which is a string
value.

But the seperate values have been obtained by using

sscanf(storedTimeValue, "%d:%d:%d", &hour,&minutes,&seconds);

So now I have 3 integer values for hour,minutes and seconds.

3) I have a function which calculates the time difference between 2
time values,
but both these time values need to be seconds from 1/1/1970.

Is there any way by which,I could convert the user given time into time
in seconds from 1/1/1970,
so that I can get the difference between the system time and the user
given time.
This is not the right forum.

But you can stuff your integer values into a struct tm
and convert it to a time_t with the mktime function.

Arne

Nov 7 '06 #3
"moni" <mo*******@gmail.comwrote in message
news:11**********************@h54g2000cwb.googlegr oups.com...
This is all in C:
So why are you posting here...?
Nov 7 '06 #4

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

Similar topics

4
by: dan glenn | last post by:
Say, I want to set a cookie and have it expire an hour after it's set. It's looking like this is only possible for browsers which are in the same time zone as my server?? In other words, if I...
2
by: learning_C++ | last post by:
I programmed this code with a function "get_current_time" in the begining. When I compiled with the command g++ -Wall -g xxx.xpp -o xxx there are so many errors. please help me and thanks, ...
1
by: heirou | last post by:
I'm a novice in this subject....I've made a database that requires a time conversion. For example, if local time is 1200, determine the time in Korea. I use two fields: a date field, and a time...
6
by: DCSudolcan | last post by:
I know that a program can create and properly initialize an array of pointers to functions at build time, but can something like the following be done at build time? void foo(void); unsigned...
5
by: Paulers | last post by:
Hello, I'm working on an app that requires the functionality to convert the time in Austrailia to the time in New York (EST). I am wondering, what is the bestway to approach this in vb.net? Is...
3
by: Jason S | last post by:
is there any way to use templates to bind integer/floating point constants to a template for compile-time use? e.g. template <double conversion> class meters { const factor = conversion;
3
by: moni | last post by:
Hi, I wanted to convert a time value in the form of time_t into a readable form in C# or vice versa, in order to be able to subtract two time values and give the result in msecs. eg. I...
3
by: Evan Klitzke | last post by:
Although it is not present in ANSI C, the GNU version of stftime supports the conversion character %z, which is a time offset from GMT. The four digit time offset is required in RFC 2822...
5
by: fimarn | last post by:
I am trying to get rid of compile time error that I am getting only in RHEL5 (not in RHEL4) apparently due to the changes in the stl_list.h file. The error that I am getting is coming from the...
5
by: Grey Alien | last post by:
I need to convert timestamps that are given as the number of seconds that have elapsed since midnight UTC of January 1, 1970, (not counting leap seconds). It seems all of the std C functions...
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...
0
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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.