Questions tagged [mktime]

mktime is a function that returns the time since the UNIX epoch from a given date and time. Found in C and PHP.

Reference for the C function: https://en.cppreference.com/w/c/chrono/mktime

Reference for the PHP function: https://php.net/manual/en/function.mktime.php

308 questions
4
votes
2 answers

is c mktime different on Windows and GNU/Linux?

the following code: #include #include #include #include #include static const char * wday_abb_names[] = { "Mon", "Tue", "Wed", …
Nils
  • 9,682
  • 6
  • 46
  • 72
4
votes
3 answers

fastest way to get time_t from YYYYMMDDHHMMSS string

Is this legit? Im trying to get to a time_t as fast as possible given a string formatted like YYYYMMDDHHMMSS. static time_t ConvertToSecSince1970(char *szYYYYMMDDHHMMSS) { struct tm Tm; memset(&Tm, 0, sizeof(Tm)); Tm.tm_year =…
johnnycrash
  • 5,184
  • 5
  • 34
  • 58
4
votes
2 answers

Am I using tm/mktime wrong, and if not is there a workaround?

I think the following program should output the seconds to 1970 for the first day of every year from 1AD to 1970, preceded by the size of time_t on the system it's compiled on (CHAR_BIT is a macro so I think you can't just copy the compiled…
Camden Narzt
  • 2,271
  • 1
  • 23
  • 42
4
votes
2 answers

Better way of creating a PHP future date

Is there a quicker way of creating a date such as: echo date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+3, date("Y"))); Thanks if you can help.
Lee
  • 20,034
  • 23
  • 75
  • 102
4
votes
0 answers

Weird mktime behavior in Solaris 11.2, bug or something else?

Seems like a bug, have a look at the code first: #include #include int main() { time_t t; struct tm tm1; tzset(); time(&t); localtime_r(&t, &tm1); tm1.tm_mday = 27; tm1.tm_sec = 59; tm1.tm_min…
4
votes
1 answer

argument must be 9-item sequence, not datetime.datetime

Web app is breaking on the following line; start_time = int(time.mktime(start)) * 1000 The error is a TypeError - argument must be 9-item sequence, not datetime.datetime How to I convert my datetime.datetime to a 9-item-sequence?
Mark Corrigan
  • 544
  • 2
  • 11
  • 29
4
votes
1 answer

mktime returns wrong timestamp (off by a whole month)

I use mktime to create a unix timestamp from my current local time: #include int _tmain(int argc, _TCHAR* argv[]) { struct tm info; // 16.05.2014 info.tm_mday = 16; info.tm_mon = 5; info.tm_year = 114; // Years since 1900 //…
Boris
  • 8,551
  • 25
  • 67
  • 120
4
votes
2 answers

php - mktime or strtotime?

I'm trying to convert 2010-02 to February, 2010. But, I keep getting December, 1969 I've tried using mktime, strtotime, and some combination of the two, but still haven't been able to do it... This is what I tried most recently... $path_title =…
n00b0101
  • 6,863
  • 17
  • 42
  • 36
4
votes
1 answer

Weird mktime logic with negative seconds

I've been using mktime/localtime for time management, including some heavy arithmetic on dates/times. I noticed something very weird when providing to mktime a struct tm that contains negative values. Take the code below. There was a DST change in…
Marcin Zukowski
  • 4,281
  • 1
  • 19
  • 28
4
votes
5 answers

how to convert date and time to timestamp in php?

i have a date '07/23/2009' and a time '18:11' and i want to get a timestamp out of it : here is my example: date_default_timezone_set('UTC'); $d = str_replace('/', ', ', '07/23/2009'); $t = str_replace(':', ', ', '18:11'); $date = $t.', 0,…
Patrioticcow
  • 26,422
  • 75
  • 217
  • 337
3
votes
5 answers

How would I fix the last day of the month errors that result with this php code?

The code below is what I'm using for a website menu which moves the link for the current month's page to the top of the link list on the change of the month. But this fails on the 31st of some months, such as April; I get two links to the same month…
markratledge
  • 17,322
  • 12
  • 60
  • 106
3
votes
1 answer

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 nDST, bool isUTC) { assert(nYear >= 1900); …
IFThenElse
  • 131
  • 1
  • 10
3
votes
0 answers

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 to get current timezone, which I think can reduce…
calvin
  • 2,125
  • 2
  • 21
  • 38
3
votes
2 answers

PHP Mktime error

I'm all of a sudden getting the following error on a site that I've done, which has been working fine so far: A PHP Error was encountered Severity: Warning Message: mktime() [function.mktime]: It is not safe to rely on the system's timezone…
Ali
  • 261,656
  • 265
  • 575
  • 769
3
votes
2 answers

Why php timestamp behave like this? 03/November/1985

I was trying to make my own php mktime(); using my default timezone *(America/Sao_Paulo)*. It was working ok, but I noticed that some timestamps had one hour more than it should be. So I tracked down and find out this date where the script starts to…
Ravan Scafi
  • 6,382
  • 2
  • 24
  • 32
1 2
3
20 21