mktime

Calculate date for Monday of current week

旧巷老猫 提交于 2021-02-16 19:41:46
问题 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 the cleanest way to determine the date. Having said that, does anyone see any reason why the code would be wrong or not work? ** <?php date_default_timezone_set("America/New_York"); $day = date("w"); if( $day == 1 ) {$day -= 0;} if( $day == 2 ) {$day

linux时间函数

允我心安 提交于 2020-02-21 14:26:21
我们在编程中可能会经常用到时间,比如取得系统的时间(获取系统的年、月、日、时、分、秒,星期等),或者是隔一段时间去做某事,那么我们就用到一些时间函数。 linux下存储时间常见的有两种存储方式,一个是从1970年到现在经过了多少秒,一个是用一个结构来分别存储年月日时分秒的。 time_t 这种类型就是用来存储从1970年到现在经过了多少秒,要想更精确一点,可以用结构struct timeval,它精确到微妙。 struct timeval { long tv_sec; /*秒*/ long tv_usec; /*微秒*/ }; 而直接存储年月日的是一个结构: struct tm { int tm_sec; /*秒,正常范围0-59, 但允许至61*/ int tm_min; /*分钟,0-59*/ int tm_hour; /*小时, 0-23*/ int tm_mday; /*日,即一个月中的第几天,1-31*/ int tm_mon; /*月, 从一月算起,0-11*/ int tm_year; /*年, 从1900至今已经多少年*/ int tm_wday; /*星期,一周中的第几天, 从星期日算起,0-6*/ int tm_yday; /*从今年1月1日到目前的天数,范围0-365*/ int tm_isdst; /*日光节约时间的旗标*/ }; 需要特别注意的是

php 时间问题

情到浓时终转凉″ 提交于 2020-01-26 02:32:46
获得简单的日期 date() 函数的格式参数是必需的,它们规定如何格式化日期或时间。 下面列出了一些常用于日期的字符: d - 表示月里的某天(01-31) m - 表示月(01-12) Y - 表示年(四位数) 1 - 表示周里的某天 其他字符,比如 "/", "." 或 "-" 也可被插入字符中,以增加其他格式。 下面的例子用三种不同方法格式今天的日期: 实例 <?php echo "今天是 " . date("Y/m/d") . "<br>"; echo "今天是 " . date("Y.m.d") . "<br>"; echo "今天是 " . date("Y-m-d") . "<br>"; echo "今天是 " . date("l");//L的小写 ?>效果: 获得简单的时间 下面是常用于时间的字符: h - 带有首位零的 12 小时小时格式 i - 带有首位零的分钟 s - 带有首位零的秒(00 -59) a - 小写的午前和午后(am 或 pm) 下面的例子以指定的格式输出当前时间: 实例 <?php echo "现在时间是 " . date("h:i:sa"); ?> 通过 PHP mktime() 创建日期 date() 函数中可选的时间戳参数规定时间戳。如果您未规定时间戳,将使用当前日期和时间(正如上例中那样)。 mktime() 函数返回日期的 Unix

mktime and tm_isdst

◇◆丶佛笑我妖孽 提交于 2020-01-21 01:15:07
问题 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

【Python】Python time mktime()方法

风格不统一 提交于 2020-01-15 19:00:58
描述 Python time mktime() 函数执行与gmtime(), localtime()相反的操作,它接收struct_time对象作为参数,返回用秒数来表示时间的浮点数。 如果输入的值不是一个合法的时间,将触发 OverflowError 或 ValueError。 语法 mktime()方法语法: time.mktime(t) 参数 t -- 结构化的时间或者完整的9位元组元素。 返回值 返回用秒数来表示时间的浮点数。 实例 以下实例展示了 mktime() 函数的使用方法: #!/usr/bin/python import time t = (2009, 2, 17, 17, 3, 38, 1, 48, 0) secs = time.mktime( t ) print "time.mktime(t) : %f" % secs print "asctime(localtime(secs)): %s" % time.asctime(time.localtime(secs)) 以上实例输出结果为: time.mktime(t) : 1234915418.000000 asctime(localtime(secs)): Tue Feb 17 17:03:38 2009 来源: https://www.cnblogs.com/yanglang/p/7611405.html

leading 0 in month parameter making wrong output

筅森魡賤 提交于 2020-01-10 06:06:07
问题 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 回答1: 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

c time类型详解

元气小坏坏 提交于 2020-01-09 23:03:16
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> linux下存储时间常见的有两种存储方式,一个是从1970年01月01日 0:00:00到现在经过了多少秒,一个是用一个结构来分别存储年月日时分秒的。time_t 这种类型就是用来存储从1970年到现在经过了多少秒,要想更精确一点,可以用结构struct timeval,它精确到微妙。 struct timeval { long tv_sec; /*秒*/ long tv_usec; /*微秒*/ }; 而直接存储年月日的是一个结构: struct tm { int tm_sec; /*秒,正常范围0-59, 但允许至61*/ int tm_min; /*分钟,0-59*/ int tm_hour; /*小时, 0-23*/ int tm_mday; /*日,即一个月中的第几天,1-31*/ int tm_mon; /*月, 从一月算起,0-11*/ 1+p->tm_mon; int tm_year; /*年, 从1900至今已经多少年*/ 1900+ p->tm_year; int tm_wday; /*星期,一周中的第几天, 从星期日算起,0-6*/ int tm_yday; /*从今年1月1日到目前的天数,范围0-365*/ int tm_isdst; /*日光节约时间的旗标*/ }; 需要特别注意的是

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

落花浮王杯 提交于 2020-01-04 03:54:25
问题 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 executable around and assume it's correct though in practice everything uses 8 bit char s these days). #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> void do_time(int year) { time_t utc; struct tm tp;

Displaying the list of months using mktime for the year 2012

戏子无情 提交于 2020-01-01 01:14:26
问题 Am am current facing a problem that need a solution ASAP. I am trying to list all months of the current year(2012) by using the following code: for ($m=1; $m<=12; $m++) { $month = date('F', mktime(0,0,0,$m)); echo $month. '<br>'; } But am getting the following unexpected output: January March March May May July July August October October December December What am I doing wrong please help!!! 回答1: Try this: for ($m=1; $m<=12; $m++) { $month = date('F', mktime(0,0,0,$m, 1, date('Y'))); echo

Get week number (in the year) from a date PHP

房东的猫 提交于 2019-12-28 02:31:32
问题 I want to take a date and work out its week number. So far, I have the following. It is returning 24 when it should be 42. <?php $ddate = "2012-10-18"; $duedt = explode("-",$ddate); $date = mktime(0, 0, 0, $duedt[2], $duedt[1],$duedt[0]); $week = (int)date('W', $date); echo "Weeknummer: ".$week; ?> Is it wrong and a coincidence that the digits are reversed? Or am I nearly there? 回答1: Today, using PHP's DateTime objects is better: <?php $ddate = "2012-10-18"; $date = new DateTime($ddate);