311 questions
1
vote
1
answer
78
views
Why does converting a `time_t` via `localtime()` and `mktime()` sometimes not return the same value?
I was trying to round-trip a time_t through struct tm *localtime(time_t t) and then time_t mktime(struct tm *tm).
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
bool ...
5
votes
1
answer
220
views
mktime() call never returns. Library bug?
Considering local time.
In testing some time code with the potential hundreds of time zones, some of them result in a mktime() call that never returns for select values!
Detail: Code never returns ...
0
votes
1
answer
157
views
mktime resulting in OverflowError: mktime argument out of range
When attempting to get a time using mktime, I get a overflow exception. This occurs on a Debian docker image, but not on my host machine:
docker pull python:3.9.7
https://hub.docker.com/layers/...
1
vote
1
answer
78
views
C++ - Running same mktime() logic in 2 different ways giving unexpected result
I am converting a time in string to long time using strptime() and mktime. Strangely, using the same code in two different ways is giving different results. The values of struct tm is same in both the ...
0
votes
1
answer
122
views
mktime causing overflowError due to daylight savings time
I'm currently getting an Overflow error on the following code when daylight savings is set to true. I've tried a number of date/time combinations and it appears to only be the 9th parameter ("...
0
votes
1
answer
285
views
Parsing datetime string with UTC offset to time_t
This question is hinted at in this one, but the answer to that question doesn't answer this question at all, and I've conflicting suggestions and hints scattered around.
My problem is relatively ...
0
votes
1
answer
244
views
Converting c++ tm struct and mktime to C#
I'm converting some c++ to c# code. I cannot reproduce equivalent values when converting from the tm struct and mktime() to c#.
Example:
Both versions use the same values:
int year = 2022;
int month = ...
1
vote
3
answers
547
views
How can I convert the day of the year (365 days) equivalent date December 31
how can i use the c++ library such as mktime() to convert day to dates instead of making my own algorithm
1
vote
1
answer
125
views
mkTime() function does not pick correct timezone c++
I am getting an input date from user and convert it into tm struct, (setting is_dst, timezone and gmtoff parameters of tm struct using local time), but when I am using mkTime to get epoch value it ...
0
votes
1
answer
476
views
Get File's Epoch timestamp, convert to DateTime, to string, and then to the identical epoch float with microsecond precision
I want to take a file's epoch timestamp float (e.g., "1661796943.8816772" from "os.stat(__file__).st_mtime"), and convert that float to what I think is called a DateTime string, ...
0
votes
0
answers
247
views
mktime returning the wrong time
I have two functions for creating a date string, and parsing a date string. The creation works, but the parser seems to add 5 hours to the time. For context, my time zone is EST, 5 hours behind GMT. ...
0
votes
1
answer
172
views
Month auto increment using mktime and timegm functions in C++
I'd like to convert a string date (UTC) to a timestamp using C++.
It works fine except for the month, which is auto incremented by one.
If the string is 20221222074648, for 2022-12-22 07:46:48, the ...
1
vote
1
answer
967
views
How to get local time in seconds (unix epoch)?
I am trying to get the local time in seconds (unix epoch) when a timezone is set.
For e.g.
1643371200 is 2022-01-28 12:00:00 with UTC0
this can be read via gettimeofday(tv, NULL) as seconds with the ...
3
votes
1
answer
143
views
mktime returns -1 but valid data
I try to find a way for a default date (if date is not valid).
Common way works fine:
set(2022,6,17,12,12,0,0,0)
void KTime::Set(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec, int ...
0
votes
1
answer
273
views
How can I change file's last access?
How can I change the file's last access by utime and mktime in linux ?
(for example, to update the file's last access to:
11 (seconds) : 11 (minutes) : 11 (hour) : 11 (day) : 11 (month) : 1500 (year) ...
1
vote
3
answers
2k
views
mktime() for non-local timezone
In C the function mktime() returns the epoch time according to the local timezone (the input struct is locally formatted).
The function timegm() returns the epoch time according to the UTC time (the ...
0
votes
1
answer
299
views
Chaining localtime and mktime in jq
If I do:
$ jq -cn 'now | localtime'
[2022,3,12,21,9,29.65448808670044,2,101]
It correctly gives the "broken down time" representation of current local time.
But If I do:
$ jq -cn 'now | ...
1
vote
0
answers
114
views
"OverflowError: mktime argument out of range" on python:3 docker image
I'm using time.mktime() to get dates in a certain format to use a 3rd-party API.
I can reproduce an overflow error on the python:3 docker images, which I don't see when running locally on ubuntu LTS (...
1
vote
2
answers
75
views
mktime causes overflow in SLES 15 SP3
SLES 15 SP3 makes use of glibc 2.31 and our convert time code using mktime is failing with ulong overflow. Can anyone let us know if we are missing something here. Or do we have any other alternative ...
1
vote
0
answers
336
views
difftime returns 0 in C++
I am trying to calculate the elapsed time between the date a book was borrowed and today, but difftime always returns 0.
This is what I have :
#include <string>
#include <iostream>
#...
0
votes
0
answers
181
views
How to convert one country time stamp into another country timestamp without using tzset() and handle DST properly in C?
Lets assume my application is running in one country(src : India), My friends who live in European country wants to read some specific data from my application in his country time stamp i.e german ...
0
votes
1
answer
304
views
mktime() returns an incorrect value right after entering DST
The following snippet code is from rtc.c in busybox-1.22.1.
In my case the utc is always 0, so this function is just doing a conversion from struct tm to time_t.
time_t FAST_FUNC rtc_tm2time(struct tm ...
3
votes
1
answer
693
views
How to improve performance of mktime?
I find mktime cost too much time on __tz_convert which will read /etc/localtime every time to get current timezone.
However, if we assume timezone never change, if only take one call to __tz_convert ...
2
votes
4
answers
2k
views
Have mktime() ignore DST and local time zone in C++
Our system receives data from a vendor in ASCII format "20210715083015". This time is US Eastern time, and is already adjusted for Daylight Savings.
Our backend needs this time in ...
1
vote
2
answers
846
views
How to find Time Duration between two dates with Hours minutes and seconds in C++ 11?
I need to find the time difference between two given dates.
I have tried the following code but not able to convert it into hours mins secs
const char *time_details = "06/10/2021 16:35:...
1
vote
3
answers
235
views
Same function outputs different results when calculating difference between two timestamps
I'm currently facing a weird issue where the same function outputs a different result. The function is supposed to calculate the time difference between a provided date and the current time. Since ...
0
votes
1
answer
131
views
Converts January 1, 0001 to the timestamp of the time library
by python, i try to calculate the number of days from December 31, 9999 to January 1, 0001
import time
def days_diff(a, b):
timestr_1 = "{}, {}, {}".format(a[0], a[1], a[2])
time_1 =...
0
votes
1
answer
438
views
How to compare GMT time and local time in C?
my server uses local time of Prague (+ 2 hours) and visitor's request uses GMT time.
In code I want to compare these times but for that I need to convert them to the same time zone. How to do it? When ...
2
votes
1
answer
2k
views
ERROR : OverflowError: mktime argument out of range
timestamp = []
for d, t in zip(data['Date'], data['Time']):
try:
ts = datetime.datetime.strptime(d+' '+t, '%m/%d/%Y %H:%M:%S')
timestamp.append(time.mktime(ts.timetuple()))
...
-1
votes
1
answer
222
views
PHP Mktime shows 2 March's when I dump foreach month
I've been using the following function fine until the other day when the clocks went forward:
function months($month_format="F") {
$array = array();
for ($i = 1; $i <=12; $i++) {
$...
1
vote
1
answer
144
views
MKTIME always return -1 (Window10_64bit / MSVS2019 / C++)
I have problem..
I can not understand why Function MKTIME always return -1
#include <Windows.h>
#include <stdio.h>
#include <time.h>
using namespace std;
int main() {
...
1
vote
0
answers
220
views
Conversion to UTC timezone in C++ leaves the time intact (regardless of the original timezone)
I am working with a dataset that contains the following information: date and time in the form "yyyy-mm-dd", "hh:mm". It also contains the name of the US state where the time has ...
0
votes
1
answer
430
views
Converting time string to seconds in C++ issues
I'm writing a C++ application on an embedded ARM device running Embedded Linux.
I am trying to convert a date and time string to seconds, subtract it from the current time in seconds, and taking ...
5
votes
4
answers
955
views
Why does mktime give me an hour less?
I would like to see if at 00:00:00 on January 1, 1970 it actually corresponds to 0 seconds, and I wrote the following:
#include <stdio.h>
#include <time.h>
int main(void) {
int year = ...
0
votes
1
answer
135
views
mktime() overwrite time_t in C
I have a problem with mktime in c:
time_t t_fim;
time(&t_fim);
struct tm* p_fim;
struct tm* c_fim;
p_fim = localtime(&t_fim);
c_fim = localtime(&t_fim);
......
p_fim->tm_year = ano-...
2
votes
1
answer
86
views
mktime or tz database unexpected return for 1941
mktime returns for july 3rd 1941 (00:00:00) and july 4th 1941 (00:00:00) are unexpected.
The difference between the two is 82800 seconds, lacking a full hour (3600).
The C program diff1941.c (see ...
0
votes
1
answer
169
views
Strange behavior of mktime() when using passing parameter created by malloc
Below I have four functions.
first() and second() initialize only the year, mon & mday of structure tm.
first_p() and second_p allocate memory using malloc, then assign year, mon & mday.
All ...
0
votes
2
answers
128
views
Why is time conversion between epoch seconds and string changing time by 1 calendar year?
I am using the time module of python3 to convert time between seconds and formatted string. Python functions used to generate string are localtime and strftime. To generate the time in seconds, I use ...
2
votes
1
answer
272
views
PHP: strtotime vs mktime speed for getting 1 month ago
Which is faster for something simple such as getting the time from one month ago.
I can do:
strtotime('-1 month');
or
mktime(1, 1, 1, date("n") - 1);
0
votes
0
answers
80
views
Getting the First Sunday in any Given Year in PHP [duplicate]
I'm making a list of all the weeks in any year starting with Sunday. They year is entered and then the weeks are measured. The problem is that Sundays don't always occur on the same day, so using ...
-1
votes
1
answer
260
views
C - mktime() returns -1 where it shouldn't
I'm trying to write a function that finds the difference in days between the current date and the date given in a formated string (like dd.mm.yy H:M:S), but mktime returns -1 every single time. Tried ...
-1
votes
1
answer
499
views
How to make `mktime` format with milliseconds?
I need make 24 frames per second with PHP ffmpeg. This is current format of
$t = mktime(0, 0, 0, 1, 1, 98);
Later I use this function
exec("/usr/local/bin/ffmpeg -ss " . date("H:i:s", $t) . " -i {$...
2
votes
3
answers
5k
views
Read time from string as GMT in C++
I am writing current GMT time as string as follow :
const std::time_t now = std::time(nullptr);
std::stringstream ss;
ss << std::put_time(std::gmtime(&now), "%Y-%m-%d %H:%M:%S");
...
1
vote
1
answer
1k
views
Convert a time string with DST to UTC timestamp
I'm trying to convert a human readable time string which has been set to a specific timezone with DST (e.g Tehran +4.30/3.30) to UTC timestamp. I'm using ARM mbed-os platform on an STM device which ...
7
votes
2
answers
2k
views
Fast way to transform datetime strings with timezones into UNIX timestamps in C++
I want to convert a huge file containing datetime strings to seconds since UNIX epoch (January 1, 1970) in C++. I need the computation to be very fast because I need to handle large amount of ...
1
vote
2
answers
289
views
Strange mktime() behaviour
Why mktime() convert 31/03/2019 02:00 to 01:00 with tm.tm_isdst = 1 with CET timezone?
I think this is an invalid combination.
#include <stdio.h>
#include <time.h>
#include <stdlib.h&...
0
votes
1
answer
292
views
mktime returns the same value in different timezones PHP
Usually this question has the opposite sense. But, I've faced with problem that, somehow mktime() function in PHP always brings me UTC timestamp despite of changing default timezone. In other words ...
0
votes
1
answer
286
views
C: add days to dates OS-independent, before 1970
I want to use mktime to add days to my date. Code taken from here, tm struct initialization from here. This code woks on Linux (gcc):
#include <stdio.h>
#include <time.h>
int main(int ...
0
votes
2
answers
533
views
mktime() returning a huge amount of seconds
In a simple test getting the elapsed time in seconds since de Unix Epoch (01/01/1970 00:00:00 UTC) to 22 of February of 2019, it has returned a huge number of 18446744072104596016
Why not just ...
-2
votes
2
answers
2k
views
mktime() expects at most 6 parameters, 7 given in [duplicate]
The Code:
$morningstarts = 9;
$eveningends = 22;
$dst_change = is_dst($month,$day,$year);
$am7=mktime($morningstarts,0,0,$month,$day,$year,is_dst($month,$day,$year,$morningstarts));
$pm7=mktime($...