mktime

how to convert date and time to timestamp in php?

纵然是瞬间 提交于 2019-12-06 09:35:33
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, '.$d; echo $date; echo '<br>'; echo $x = mktime("$date"); the issue is that $x gives me the current timestamp. any ideas? divyang asodiya it gives error because mktime function require all values of numbers only and this function gives only date . if you try like $h = 18; $i = 11; $s = 00; $m = 07; $d =23; $y = 2009; echo date("h-i-s-M-d-Y",mktime($h,$i,$s,

is c mktime different on Windows and GNU/Linux?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 08:39:55
问题 the following code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <sys/time.h> static const char * wday_abb_names[] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", }; static void mb_setenv(const char *name, const char *value) { #if !(defined _WIN32) || defined HAVE_SETENV setenv(name, value, 1); #else int len = strlen(name)+1+strlen(value)+1; char *str = malloc(len); sprintf(str, "%s=%s", name, value); putenv(str); #endif } static void mb_unsetenv

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

无人久伴 提交于 2019-12-06 04:01:14
问题 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 = 0; referenceDateComponent.tm_min = 0; referenceDateComponent.tm_sec = 0; referenceDateComponent.tm_year = 89; referenceDateComponent.tm_mon = 11; referenceDateComponent.tm_mday = 31; referenceDate = mktime(&referenceDateComponent); long seconds = difftime(dateNow,

Confusing behaviour of mktime on Linux?

旧巷老猫 提交于 2019-12-05 10:13:44
I am using the mktime(struct tm*) function in Suse 10. Now, I am noticing some strange behaviour when daylight saving time is enabled. Let's say I have enabled daylight saving time to begin on Sep 15 at 18:10 and the daylight correction is for 30 minutes. Now, when I call mktime with tm structure having the date as Sep 15 18:10 and tm_isdst is set to 0, then I get back the same values in the tm structure only with the tm_isdst set to 1. But, if the pass the date as Sep 15 18:10 with tm_isdst set to 1, then I find the time changed to 17:40. This correction in the tm structure is noticed for

PHP strtotime() function that accepts a format?

跟風遠走 提交于 2019-12-04 11:40:30
问题 strtotime() in PHP works great if you can provide it with a date format it understands and can convert, but for example you give it a UK date it fails to give the correct unix timestamp. Is there any PHP function, official or unofficial, that can accept a format variable that tells the function in which format the date and time is being passed? The closest I have come to doing this is a mixture of date_parse_from_format() and mktime() // Example usage of the function I'm after //Like the date

mktime returns wrong timestamp (off by a whole month)

自作多情 提交于 2019-12-04 04:08:43
问题 I use mktime to create a unix timestamp from my current local time: #include <time.h> 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 // 08:00:00 Uhr info.tm_hour = 8; info.tm_min = 0; info.tm_sec = 0; // Convert to Unix timestamp info.tm_isdst = -1; time_t timestamp = mktime(&info); printf("Timestamp: %i", timestamp); } This gives me: 1402898400 When converting this back to a human readable time

PHP strtotime() function that accepts a format?

大憨熊 提交于 2019-12-03 08:10:34
strtotime() in PHP works great if you can provide it with a date format it understands and can convert, but for example you give it a UK date it fails to give the correct unix timestamp. Is there any PHP function, official or unofficial, that can accept a format variable that tells the function in which format the date and time is being passed? The closest I have come to doing this is a mixture of date_parse_from_format() and mktime() // Example usage of the function I'm after //Like the date() function but in reverse $timestamp = strtotimeformat("03/05/2011 16:33:00", "d/m/Y H:i:s"); If you

Why is mktime() changing the year day of my tm struct?

被刻印的时光 ゝ 提交于 2019-12-01 01:18:26
问题 I read in two strings with a Year, the Julian Day (year day), hour, minute, and an observation. I pull the relevant variables out using sscanf: sscanf(tide_str1.c_str(), "%d %d %d %d %Lf", &y1, &j1, &h1, &m1, &obs1); sscanf(tide_str2.c_str(), "%d %d %d %d %Lf", &y2, &j2, &h2, &m2, &obs2); For this particular data set, the values are 2011 083 23 22 1.1 I then create and populate a tm structure, and run mktime, with cout calls on the day in between and it changes from 083 to 364. int y1=2011,

mktime and tm_isdst

落花浮王杯 提交于 2019-11-30 11:36:42
I saw a lot of different views so thought of asking here. I read man mktime : (A positive or zero value for tm_isdst causes mktime() to presume initially that summer time (for example, Daylight Saving Time) is or is not in effect for the specified time, respectively. A negative value for tm_isdst causes the mktime() function to attempt to divine whether summer time is in effect for the specified time. My question is, shouldn't tm_isdst be kept as -1 to let the system decide if its dst or not and that way the code becomes dst agnostic? Am I missing something? I believe the original reason for

leading 0 in month parameter making wrong output

家住魔仙堡 提交于 2019-11-29 17:24:20
Why the leading zero in the month parameter making wrong output? echo date("Y-m-d", mktime(0, 0, 0, 09, 23, 2013));//output 2012-12-23 echo date("Y-m-d", mktime(0, 0, 0, 9, 23, 2013));//output 2013-09-23 From https://bugs.php.net/bug.php?id=55327 : Numbers with leading 0's are octal. 08 is an invalid value. See http://php.net/integer If you prefix a number with a leading 0 , it marks the number as Octal . The octal numeral system uses the digits 0 to 7. So, 08 and 09 doesn't exist and are invalid. The second statement is correct, and that's the correct method: echo date("Y-m-d", mktime(0, 0, 0