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

How to compute time into integer?

Hey, noob here... (I'm only 13, so be cool :)

I need to compute the time value in seconds: the time will be
variable, but the format will be like this--> 2007.08.24 13:38:39

I need TO TURN THIS into INTEGER! (I want to do this in C)

Can anyone help?

Thx!

Daikide
Aug 29 '07 #1
4 1449
Ganon11
3,652 Expert 2GB
You will have to use some conversions. Think about what a year is - 365 days. A day is 24 hours, an hour is 60 minutes, and a minute is 60 seconds. Using these values, you should be able to convert the timestamp into total seconds. The other problem you have is how to actually get these values from the input - which depends greatly on how you want your program to work.

Are you reading this in all at once into a string? Is this user input or from a file? Information like this will help experts help you ;)
Aug 29 '07 #2
sicarie
4,677 Expert Mod 4TB
I haven't done this personally, so I can't point you towards anything I've used or seen used, but why not look for an already created 'date' or 'time' class? They usually have conversions or methods that make comparisons easier...
Aug 29 '07 #3
You will have to use some conversions. Think about what a year is - 365 days. A day is 24 hours, an hour is 60 minutes, and a minute is 60 seconds. Using these values, you should be able to convert the timestamp into total seconds. The other problem you have is how to actually get these values from the input - which depends greatly on how you want your program to work.

Are you reading this in all at once into a string? Is this user input or from a file? Information like this will help experts help you ;)

I have a file with a timestamps and the data. but I created a panel where I will just paste the timestamps(Starting and final timestamps) so the data in between those two inputs gets processed.

So I guess it's a user input...

Unfortunately we don't have a programming class at school so.. eeh (0_0)

Thanks a lot!!! :)

//


I found something like this:


ime_t StringToTimestamp(const char *time_string)
{
struct tm time_in = {0};
char *tmp = NULL;

time_in.tm_year = strtoul(time_string + 6, &tmp, 10) - 1900;
time_in.tm_mon = strtoul(time_string, &tmp, 10) - 1;
time_in.tm_mday = strtoul(time_string + 3, &tmp, 10);
/* Convert the date in seconds (since 1/1/1970) */

return mktime(&time_in);

//} /* StringToTimestamp */

-----------------

But I can't say I understand everything what's going on... trying to read some things in help...
Aug 29 '07 #4
RRick
463 Expert 256MB
Take a look at the <time.h> C/system header file. This has a lot of routines that deal with time.

Your tm structure is just one of many structures to manipulate time. There is also:

  • time_t time( time_t *loc) where time_t is the current time in an integer format
  • strftime takes a tm structure and formats it via a statement that looks a lot like printf.
  • Once you get time into a tm or time_t stucture, you can compare them and find the difference between two times
  • I haven't seen anything in C that will parse a char string into the time structure.
Aug 29 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: pentium77 | last post by:
Hi, Just wondering what's the algo used to compute hashcode in Java ? Does anybody here know ? Thanks, -MK.
13
by: Huey | last post by:
Hi All, I need to compute the current time value in seconds: the current time is 12/16/2003, and it's time value in integer should around 1071560616 seconds since 1/1/1970. It is easy to get...
2
by: Michael Howes | last post by:
I have a single DataTable in a DataSet. It has 4 columns and i'd like to get a handful of counts of unique items in 3 of the 4 columns. Can a DataTables Select or Compute methods to COUNT DISTINCT?...
1
by: skirkby | last post by:
This will be obvious to some - but not me I'm afraid... I am using an SQL data link from my ASP application to a SPROC - this all works fine on standard SELECT statements and JOIN in to a...
2
by: Maciej Bliziñski | last post by:
Hello, I started to write the query that should compute the median. Surprisingly, I get following error message: "server closed the connection unexpectedly This probably means the server...
1
by: M P | last post by:
Hi! How can I compute time between two numbers? Time A: 16-Apr-2006 08:00:00 Time B: 17-Apr-2006 16:00:10 Answer: Days, Time, Sec (1 day, 8 hours, 0 mins, 10 secs)
6
by: Spoon | last post by:
Hello, Consider: #define BUFFER_SIZE 1234 /* or some other value */ uint8_t buffer; int do_stuff(uint8_t *buf); where do_stuff() does something with each octet in the buffer.
27
by: csledge | last post by:
Hi, I am trying to compute a 64 bit result from 2 32 bit registers, How do I get the carry into the higher word ? Also is %lld correct ? #include<stdio.h> long long int64( long x, int y);...
2
by: milirica | last post by:
I have a code, where I should compute the App.Compute Time, for n=1,5,10,20,30,40,50.Is there any GOOD EXPERT that can make this clear to me ? If yes than PLease write here The code is: #include...
0
by: ccarter45 | last post by:
I need to compute the differences in color between 2 pictures. Also, I need to write a method that computes a useful difference color of two colors (where the colors and their difference will be...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
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...
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: 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: 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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.