这篇文章主要为大家详细介绍了PHP利用strtotime函数用法示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小玲来看看吧!
在前面的<如何使用PHP计算上一个月的今天>一文中, 我们提到strtotime函数在使用strtotime(”-1 month”)求上一个月的今天时会出一些状况,代码如下:
echo date("Y-m-d H:i:s", strtotime("feb", strtotime("2011-03-31")));
代码如下:
echo date("Y-m-d H:i:s", strtotime("second sunday", strtotime("2011-01-01"))), "<br />";
代码如下:
switch (time->relative.first_last_day_of) {
case 1: /* first */
time->d = 1;
break;
case 2: /* last */
time->d = 0;
time->m++;
break;
}
代码如下:
echo date("Y-m-d H:i:s", strtotime("previous sunday", strtotime("2011-02-01"))), "<br />";
代码如下:
echo date("Y-m-d H:i:s", strtotime("last sunday", strtotime("2011-02-05"))), "<br />";
代码如下:
echo date("Y-m-d H:i:s", strtotime("last day", strtotime("2000-02-01"))), "<br />";
代码如下:
echo date("Y-m-d H:i:s", strtotime("back of 24", strtotime("2011-02-01"))), "<br />";
echo date("Y-m-d H:i:s", strtotime("front of 24", strtotime("2011-02-01"))), "<br />";
代码如下:
PHP_FUNCTION(strtotime)
// 处理输入,对于是否有第二个参数有没的处理
// 调用相关函数,实现字符串的解析和结果计算
// 返回结果
}
代码如下:
'yesterday'
{
DEBUG_OUTPUT("yesterday");
TIMELIB_INIT;
TIMELIB_HAVE_RELATIVE();
TIMELIB_UNHAVE_TIME();
s->time->relative.d = -1;
TIMELIB_DEINIT;
return TIMELIB_RELATIVE;
}
代码如下:
typedef struct Scanner {
int fd;
uchar *lim, *str, *ptr, *cur, *tok, *pos;
unsigned int line, len;
struct timelib_error_container *errors;
struct timelib_time *time;
const timelib_tzdb *tzdb;
} Scanner;
typedef struct timelib_time {
timelib_sll y, m, d; /* Year, Month, Day */
timelib_sll h, i, s; /* Hour, mInute, Second */
double f; /* Fraction */
int z; /* GMT offset in minutes */
char *tz_abbr; /* Timezone abbreviation (display only) */
timelib_tzinfo *tz_info; /* Timezone structure */
signed int dst; /* Flag if we were parsing a DST zone */
timelib_rel_time relative;
timelib_sll sse; /* Seconds since epoch */
unsigned int have_time, have_date, have_zone, have_relative, have_weeknr_day;
unsigned int sse_uptodate; /* !0 if the sse member is up to date with the date/time members */
unsigned int tim_uptodate; /* !0 if the date/time members are up to date with the sse member */
unsigned int is_localtime; /* 1 if the current struct represents localtime, 0 if it is in GMT */
unsigned int zone_type; /* 1 time offset,
* 3 TimeZone identifier,
* 2 TimeZone abbreviation */
} timelib_time;
typedef struct timelib_rel_time {
timelib_sll y, m, d; /* Years, Months and Days */
timelib_sll h, i, s; /* Hours, mInutes and Seconds */
int weekday; /* Stores the day in 'next monday' */
int weekday_behavior; /* 0: the current day should *not* be counted when advancing forwards; 1: the current day *should* be counted */
int first_last_day_of;
int invert; /* Whether the difference should be inverted */
timelib_sll days; /* Contains the number of *days*, instead of Y-M-D differences */
timelib_special special;
unsigned int have_weekday_relative, have_special_relative;
} timelib_rel_time;
代码如下:
reltextunit = (('sec'|'second'|'min'|'minute'|'hour'|'day'|'fortnight'|'forthnight'|'month'|'year') 's'?) | 'weeks' | daytext;
relnumber = ([+-]*[ /t]*[0-9]+);
relative = relnumber space? (reltextunit | 'week' );
代码如下:
case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break;
本文来自:http://www.q1010.com/173/15686-0.html
注:关于PHP利用strtotime函数用法示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。