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
3
votes
3 answers

Conversion of date 8-DEC-17 to 08/12/2017 is giving 07/12/2017 in python

I'm trying to format the datetime in python, and this is what I was trying: import time datestr = "8-DEC-17" v=time.strptime(datestr,"%d-%b-%y") l = time.mktime(v) print(time.strftime("%d/%m/%y ", time.gmtime(l))) The output of this code is…
Divya
  • 55
  • 4
3
votes
6 answers

Conversion to unix timestamp incorrect

I have a function that I wrote (if there is a good standard substitute, please let me know...) time_t get_unix_time(string time_str) { time_t loctime; time(&loctime); struct tm *given_time; time_str = time_str.substr(0,…
Sagar
  • 9,456
  • 6
  • 54
  • 96
3
votes
2 answers

Alternative to mktime in C++

uint64_t timestamp_nanoseconds = 634019142119225390; time_t result = timestamp_nanoseconds / 1000000000; struct tm * timeinfo = gmtime(&result); struct tm dateInfo ; dateInfo.tm_mday = timeinfo->tm_mday ; dateInfo.tm_mon = timeinfo->tm_mon…
Balan K
  • 356
  • 2
  • 11
3
votes
1 answer

IAR , localtime, mktime

I am using the DLib for your IAR-Compiler and wanted to convert a UTC-timestamp to a local timestamp. I am located in Germany hence my implementation for the __getzone-method is as followed: char const * __getzone() { return…
3
votes
1 answer

AttributeError: type object 'datetime.time' has no attribute 'mktime'

I'm getting this attribute error either because I'm importing the modules or else referencing them incorrectly. from datetime import date, timedelta, datetime, time, tzinfo with def utc2local (utc): epoch = time.mktime(utc.timetuple()) …
tamus
  • 53
  • 1
  • 1
  • 9
3
votes
1 answer

mktime : unexpected result

I want to convert a struct tm to a time_t with mktime in c. Here is my code: #include #include int main(int argc, char **argv) { struct tm _tm; time_t _t; strptime ("20160220", "%Y%m%d", &_tm); printf ("1: struct tm =>…
kdg1955
  • 305
  • 2
  • 12
3
votes
2 answers

What is an intelligent way to determine max size of a strftime char array?

How can I size the char array for strftime without trial and error? Using mktime, the timestamp size N in the example has to be greater 86, otherwise I get arbitrary dates back. e.g. N = 86 : 2013-07-13 02:41 N = 82 : 1979-05-18 13:23 How do I…
smartmic
  • 661
  • 5
  • 15
3
votes
2 answers

1 hour skipped when i add seconds manually

I know it's gonna sound you strange.. but it's happening.. I am trying mktime() function to create a seconds string: $time = mktime(21,0,0,3,29,2014); echo date("d-M, h:i A", $time); And then I add 21600 (6 Hours) seconds in it.. $newstr =…
Ahmad Sattar
  • 321
  • 2
  • 10
3
votes
2 answers

set cookie to expire at the end of current day

I want to set a cookie and have it expire at the end of the day This works, but expires after 24 hours: setcookie('route_upgrade_voted', true, time()+86400); This does not work: setcookie('route_upgrade_voted', true, mktime(24,0,0) - time());
Brad
  • 12,054
  • 44
  • 118
  • 187
3
votes
4 answers

Calculate date for Monday of current week

Goal: If current day of week is any day other than Monday, display the date of the Monday of the current week. If the current day of the week is Monday, simply display today's date. ** This is what I wrote and I think it works but is probably not…
DMSJax
  • 1,709
  • 4
  • 22
  • 35
3
votes
3 answers

Php mktime() vs date()

This is a PHP question. When I test this code echo date("d-m-y h:i:S"); on my local server and on my hosted website (these two have different time zones) they return different datetime values,as expected. But when I try this code echo…
user1800007
  • 45
  • 1
  • 5
3
votes
1 answer

php mktime gives different results for same date?

the following code: // settings 1st alternative $season = 2011; $startweek = 36; // calculation, 1st alternative // in any case Jan 1st is in 1. week $firstweekuniversal = mktime(0,0,0,1,4,$season); // I'd like to…
3
votes
1 answer

Difference between mktime and timelocal

What is the difference between these two functions? It was my understanding that those should be the same: http://www.gnu.org/software/libc/manual/html_node/Broken_002ddown-Time.html. I wrote this code to test the conversion (the Qt part is only for…
Luca Carlon
  • 9,546
  • 13
  • 59
  • 91
3
votes
1 answer

Strange behaviour with mktime producing error in June/July

I have the following ungainly code to turn a date string into another date string. //$invDate starts as a date string in format dd/mm/yyyy $dateArray = explode('/', $invDate); $invDate = $dateArray[0] .' '. date("F",mktime…
fred2
  • 1,015
  • 2
  • 9
  • 29
2
votes
3 answers

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 nanoseconds since Epoch. I'm trying to use mktime() to do the…