Questions tagged [time-t]

`time_t` is a Standard-C data type to hold the seconds since UNIX epoch, that since the 1.1.1970.

171 questions
9
votes
1 answer

Converting a time_t to NSDate object?

Is there any method provided by Apple or any technique that can convert a time_t type variable to an NSDate object?
thyrgle
9
votes
3 answers

Time into string with HH:MM:SS format (C-programming)

I need to get the current time in a "HH:MM:SS"-format into a character array (string) so I can output the result later simply with a printf("%s", timeString); I'm pretty confused on the timeval and time_t types btw, so any explanation would be…
o01
  • 5,191
  • 10
  • 44
  • 85
8
votes
3 answers

how to define a loop to be run for some seconds/minutes long

My purpose is to execute a while loop for a defined time (e.g. 90 seconds for this example). It does not have to be exactly 90 s, but 1-2 second inaccuracy is acceptable. I trued to use clock()` function for this purpose: int main(void){ …
Angs
  • 1,605
  • 2
  • 23
  • 47
8
votes
1 answer

C - How to convert time_t to tm?

I have a variable which using time_t data type. I want to convert this type into "YYYY-MM-DD HH:MM:SS". I just know if it's only works in localtime() example: char buff[20]; time_t now = time(NULL); strftime(buff, 20, "%Y-%m-%d %H:%M:%S",…
Angga
  • 95
  • 1
  • 1
  • 7
8
votes
2 answers

How to extract hours from time_t?

I want to extract hours, minutes and seconds as integer values from a time_t value representing seconds since epoch. The value for hours is not correct. Why? #include #include #include int main() { char…
Daniel Näslund
  • 2,300
  • 3
  • 22
  • 27
7
votes
2 answers

ISO 8601 to time_t conversion in C or vice versa

According to ISO 8601, time can be specified in different formats. My program does not know which exact ISO 8601 format will be specified. In this case, how can I convert it to time_t? strptime requires you to specify format (which I do not know…
hari
  • 9,439
  • 27
  • 76
  • 110
7
votes
4 answers

easy way to add 1 month to a time_t in C/C++

I have some code that uses the Oracle function add_months to increment a Date by X number of months. I now need to re-implement the same logic in a C / C++ function. For reasons I don't want/need to go into I can't simply issue a query to oracle to…
Glen
  • 21,816
  • 3
  • 61
  • 76
7
votes
2 answers

Convert double to time_t

I have a double containing seconds. I would like to convert this into a time_t. I can't find a standard function which accomplishes this. Do I have to fill out the time_t by hand?
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
6
votes
3 answers

How to use time > year 2038 on official Windows Python 2.5

The official Python 2.5 on Windows was build with Visual Studio.Net 2003, which uses 32 bit time_t. So when the year is > 2038, it just gives exceptions. Although this is fixed in Python 2.6 (which changed time_t to 64 bit with VS2008), I'd like to…
Francis
  • 11,388
  • 2
  • 33
  • 37
6
votes
2 answers

How to change the format of date and time with time_t?

time_t now = time(0); std::string h = std::string (ctime (&now)); std::cout << "\nh: " << h; Current output that I am receiving is: Thu Sep 14 10:58:26 2017 I want the output as 2017-08-26-16-10-56 What can I do to that output?
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
6
votes
3 answers

Convert Unix/Linux time to Windows FILETIME

I am once again going from Windows to Linux, I have to port a function from Windows to Linux that calculates NTP time. Seems simple but the format is in Windows FILETIME format. I sort of have an idea what the differences are but so far I can not…
Dixon Steel
  • 1,021
  • 4
  • 12
  • 27
6
votes
4 answers

How do I get time_t in GMT on Windows in C

I am writing some code that will run on multiple intercommunicating systems. I was using time() to get time_t, but this was causing problems with time zone differences between the systems, so I want to get time_t in GMT. I've been looking through…
Derek
  • 3,087
  • 1
  • 21
  • 23
5
votes
4 answers

How to calculate time differences in C++ with time_t before the epoch?

What I would like to do with my simple program is to calculate a difference in seconds between two dates. time_t referenceDate; time_t dateNow = time(0); struct tm referenceDateComponent = {0}; referenceDateComponent.tm_hour =…
BEPP1
  • 945
  • 2
  • 11
  • 15
5
votes
2 answers

Standard conformant way of converting std::time_t to System::DateTime?

I have already found several answers related to converting a std::time_t value to System::DateTime and back. However, almost all answers seem to neglect that the type of std::time_t is actually undefined in the standard. Most solutions just cast…
Excelcius
  • 1,680
  • 1
  • 14
  • 31
5
votes
2 answers

Convert MYSQL Timestamp to time_t

I'm writing a multi-threaded program that needs to be able to check if a row requires updating and act accordingly. I had problems using the built in date/time functions of MySql and so decided to just store the "lastupdate" timestamp as an integer…
Kewley
  • 527
  • 1
  • 6
  • 13
1
2
3
11 12