473,769 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Time Conversion

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(storedTi meValue, "%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 7 '06
18 3120
Asbj?rn Sæb? said:
>
The book "C Unleashed" seems to be out of print and somewhat hard to
come by.
Yes, I'm afraid that's true. "C Unleashed" went out of print earlier this
year IIRC, and as far as I know there are no plans for a re-print or a new
edition. :-(
(Sorry for the somewhat off-topic post. I tried to contact
Mr. Heathfield at the email address he specifies at the bottom of his
posts, but it came back with a message saying:
"Your message cannot be delivered to the following recipients:
Mea culpa. The mail forwarding is broken at present, and I haven't got
around to contacting the forwarder to find out why. I'll try to remember to
do that tomorrow.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: er, none at the moment.
Nov 7 '06 #11
Richard Heathfield <in*****@invali d.invalidwrites :
Asbj?rn Sæb? said:

The book "C Unleashed" seems to be out of print and somewhat hard to
come by.

Yes, I'm afraid that's true. "C Unleashed" went out of print earlier this
year IIRC, and as far as I know there are no plans for a re-print or a new
edition. :-(
OK, thanks for the information. I'll have to look around for a bit,
then.

Asbjørn
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 7 '06 #12
On Tue, 2006-11-07 at 22:23 +0100, Asbjørn Sæbø wrote:
The book "C Unleashed" seems to be out of print and somewhat hard to
come by. Can anybody (Mr. Heathfield, for example) tell me whether
there are any plans for a reprint or a new edition?

(Sorry for the somewhat off-topic post. I tried to contact
Mr. Heathfield at the email address he specifies at the bottom of his
posts, but it came back with a message saying:
"Your message cannot be delivered to the following recipients:

Recipient address: <xxx>@<xxxx>.or g.uk
Reason: Illegal host/domain name found")
I got my copy at Half Price Computer Books. I had requested it
from my library, but they denied it on the grounds that it was
"older" and "high priced".

You may find that contacting Sams Publishing will get you a
better answer than this group will.

--
Andrew Poelstra <http://www.wpsoftware. net>
For email, use 'apoelstra' at the above site.
"You're only smart on the outside." -anon.

Nov 7 '06 #13
"moni" <mo*******@gmai l.comwrites:
Why is that?

i dint get it...
You didn't get what? If you didn't get Jordan's advice to avoid
top-posting, read the following:

http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 7 '06 #14


On Nov 7, 5:53 pm, Asbjørn Sæbø <a...@stud.ntnu .nowrote:
Richard Heathfield <inva...@invali d.invalidwrites :
Asbj?rn Sæb? said:
The book "C Unleashed" seems to be out of print and somewhat hard to
come by.
Yes, I'm afraid that's true. "C Unleashed" went out of print earlier this
year IIRC, and as far as I know there are no plans for a re-print or a new
edition. :-(
OK, thanks for the information. I'll have to look around for a bit,
then.
They still have it on Amazon if you have nothing against used books.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

Nov 8 '06 #15
Jordan Abel wrote:
2006-11-07 <1162926494.233 238.42...@i42g2 000cwa.googlegr oups.com>,
<snip>
Anyway - you should be aware a tm_year value of 2006 refers to the year
3906. The proper tm_year value for this year is 106.
On Nov 7, 4:02 pm, "moni" <mons.2...@gmai l.comwrote:
Why is that?

i dint get it...

thanx..
Please don't top post. I put some of Jordan's quote above your so it
makes sense.
tm_year is the number of years since 1900. If you set tm_year to 2006,
the year will be 2006+1900=3906.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

Nov 8 '06 #16
Andrew Poelstra wrote:
On Tue, 2006-11-07 at 22:23 +0100, Asbjørn Sæbø wrote:
>The book "C Unleashed" seems to be out of print and somewhat hard to
come by. Can anybody (Mr. Heathfield, for example) tell me whether
there are any plans for a reprint or a new edition?

(Sorry for the somewhat off-topic post. I tried to contact
Mr. Heathfield at the email address he specifies at the bottom of his
posts, but it came back with a message saying:
"Your message cannot be delivered to the following recipients:

Recipient address: <xxx>@<xxxx>.or g.uk
Reason: Illegal host/domain name found")
I got my copy at Half Price Computer Books. I had requested it
from my library, but they denied it on the grounds that it was
"older" and "high priced".

You may find that contacting Sams Publishing will get you a
better answer than this group will.
Hi there, after a sale went through I have been scouring the internet
for these books. I have found them on ebay again though, brand new. You
might want to hurry as I think time is running out on this one.

http://cgi.ebay.co.uk/ws/eBayISAPI.d...MEWA%3AIT&rd=1

Pretty darn cheap too, don't touch Amazon marketplace, they know this
book is rare so they overcharge.

Good luck.
--
Reclaim Your Inbox! http://www.mozilla.org/products/thunderbird
Nov 8 '06 #17
Andrew Poelstra <ap*******@fals e.sitewrites:
On Tue, 2006-11-07 at 22:23 +0100, Asbjørn Sæbø wrote:
The book "C Unleashed" seems to be out of print and somewhat hard to
come by. [...]
I got my copy at Half Price Computer Books. [...]
I think I have managed to persuade Half Price Computer Books to sell
me a couple (one for my private bookshelf, one for work) now.
Shipping out of the US was not an option ("too large for an
"internatio nal priority envelope"), but fortunately I have relatives
over there.

Asbjørn
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 13 '06 #18
On 7 Nov 2006 10:35:37 -0800, "moni" <mo*******@gmai l.comwrote:
>
struct tm *newtime, *oldtime;

time_t result;
time_t long_time;
double elapsed_time;

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

time( &long_time ); /* Get time as long integer. */
Note that time_t must be _some_ arithmetic type, and is usually an
integer (and in Unix/POSIX is required to be), but it isn't required
to be 'long' specifically, so this name and comment could be wrong.
newtime = localtime( &long_time ); /* Convert to local time. */
oldtime = localtime( &long_time );
Warning: localtime() and also gmtime() returns (if no error) a pointer
that is permitted to be and usually is to 'static' (shared) memory.
Changing any one of these 'values', as you do just below, affects the
others. In your code you don't actually use oldtime for anything so
this error is masked, but if you want to actually use it you need to
allocate an actual struct tm, not just a pointer, and _copy_ to it.
newtime->tm_isdst = 0;
Do you really want to force DST off? Even if the current day is during
a DST/SummerTime period in a zone that uses it? If you are worried
about times on a transition day, you can set tm_isdst to -1 to tell
the library to figure out (from scratch) whether the (modified)
broken-down time you give it is during DST or not. If it is during
both and thus is ambiguous, e.g. 01:30 on the 'fall back' day under US
rules, you will lose and get the -1 return. But from the very limited
requirements statement you have given us so far, it's not at all clear
what if anything is the desired answer in that case.
newtime->tm_hour = hour;
newtime->tm_min = minutes;
newtime->tm_sec = seconds;
//newtime->tm_year = 2006;

result = mktime(&newtime );
This is wrong. You are passing the address of the pointer, not the
value of the pointer = the address of the struct. If you had
#include'd <time.has you must to make your program valid, your
compiler would (must) have detected this mismatch and given you a
'diagnostic' (in usual terms, an error or warning message).

If you do make newtime an actual struct tm, as I discussed above,
_then_ this would be right.
printf("time is %d, %d", result, long_time);
If time_t is indeed long, that is not the correct format specifier for
printf, you should use %ld. If you don't know whether it is or not,
and in portable code you cannot easily know, you can cast to and
format as the largest possible type; in C89 this is long or unsigned
long using %ld or %lu, in C99 [u]intmax_t using %jd or %ju. Fully
conforming C99 implementations are still fairly rare; ones that
implement at least fairly basic/easy features including this are
becoming more common but still not ubiquitous.
Here the result always come s to -1, ie. mktime is always returning -1.

Can you tell me the reason?
See above.

- David.Thompson1 at worldnet.att.ne t
Nov 20 '06 #19

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

Similar topics

4
11717
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 set my cookie with: setcookie('CookieName', $SomeValue, time()+3600, "/");
2
2815
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, #include <map> #include <iostream> #include <iomanip> #include <string> #include <time.h>
1
11685
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 field. I need the converted time to show up in a report. I also need the corresponding date to increment if necessary. Any ideas on how to do this would be greatly appreciated.
6
2069
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 char myArray={ (unsigned char) (foo&0xFF), (unsigned char) ((foo&0xFF00)>>8), (unsigned char) ((foo&0xFF0000)>>16),
5
4677
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 there anything in VB.net that can make this conversion? If not, is it possible to hit a time server of some sort to get the conversion? I know there are time conversion websites all over the place Im just wondering if any of them allow an...
3
2889
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
2758
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 have a time value,
3
2478
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 dates/times, and is used by a number of other programs as well. I need to convert times that use this convention to python time representations, and because Python does not support the %z time conversion character I cannot simply use the time.strptime...
5
3176
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 following code that attempts to remove an item from the list: class shm_objptr_list : public std::list < void*, SharedMemAlloc<void * > {
5
8523
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 expect positive offsets from this date and are incapable of working on dates preceeding the epoch (i.e. negative offsets) - which IMHO shows a remarkable lack of foresight - and is *just* a little bit annoying. Does anyone know of an algo I can...
0
9579
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
9422
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
10206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9851
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
7403
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
5293
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...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.