time-t

Converting days since epoch to seconds since epoch

At my new workplace, they represent a lot of dates as "days since epoch" (which I will hereafter call DSE). I'm running into issues in JavaScript converting from DSE to seconds since epoch (UNIX timestamps). Here's my function to do the conversion: function daysToTimestamp(days) { return Math.round(+days * 86400); } By way of exam...

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 get the new date. Does anyone know of a simple and reliable way of adding X number of m...

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 use 2.5 because many modules are already compiled for it. So here's my question - is the...

Writing a function to display current day using time_t?

Hi there, I've been writing a time converter to take the systems time_t and convert it into human readable date/time. Oh, and this is my second python script ever. We'll leave that fact aside and move on. The full script is hosted here. Writing converters for the year and month were fairly easy, but I've hit a serious brick wall tryin...

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 awesome:) EDIT: So I tried with strftime etc, and it kinda worked. Here is my code: time_t c...

Segmentation fault on time(0);

Hi! I'm rewriting an old program to do some new stuff, and suddenly I get a segmentation fault error on the following line of code: time_t seconds_since_time_begun = time(0); Why, oh why? Update: I have included the time.h header file in my code, and when I tried what pmg suggested below, both variables were 4 in size. When I tried...

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 in the table. However, I'm having problems converting this timestamp to time_t so that I...

How to printf a time_t variable as a floating point number?

Hi guys, I'm using a time_t variable in C (openMP enviroment) to keep cpu execution time...I define a float value sum_tot_time to sum time for all cpu's...I mean sum_tot_time is the sum of cpu's time_t values. The problem is that printing the value sum_tot_time it appear as an integer or long, by the way without its decimal part! I tried...

_USE_32BIT_TIME_T equivalent for gcc

on Visual studio I can force use of 32 bit time_t by declaring _USE_32BIT_TIME_T is there a similar equivalent for gcc? or is it always 32 bit or is it always 64 bit? ...

What primitive data type is time_t?

I do not know the data type of time_t. Is it a float double or something else? Because if I want to display it I need the tag that corresponds with it for printf. I can handle the rest from there for displaying time_t but I need to know the data type that corresponds with it. ...

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? ...

Two seperate tm structs mirroring each other

Here is my current situation: I have two tm structs, both set to the current time I make a change to the hour in one of the structs The change is occurring in the other struct magically.... How do I prevent this from occurring? I need to be able to compare and know the number of seconds between two different times -- the current time a...

C - Convert time_t to string with format YYYY-MM-DD HH:MM:SS

Hello, is there any way to convert a time_t to a string with the format YYYY-MM-DD HH:MM:SS automatically, keeping the code portable? ...

Best way to convert Unix time_t to/from abitrary timezones?

My code receives a time_t from an external source. However, that time_t isn't acutally based on UTC Epoch time, along with it I get a timezone string (eg, EDT, PST, etc), and its based on this offset'ed epoch. I need to convert this to a true UTC Epoch based time_t. Additionally, I need to be able to go in the opposite direction, taking...

How do I convert a time to tm struct instead of CTime class

Hello. I currently have code that creates a CTime object from a defined value. #define TIME_VALUE 0x301DDF00 // Aug 1, 1995 @ 04:00:00 CTime t = CTime( TIME_VALUE ); This creates the desired date of Aug 1, 1995 04:00:00 I can no longer use CTime so I am trying to use time_t and tm instead. Since the CTime constructor takes in the ...