php学习06-02
来源:互联网 发布:android快递查询源码 编辑:程序博客网 时间:2024/06/08 08:25
2 日期函数
时间戳 : 1970.1.1.0到现在的秒数
01) time int time(void) 返回当前的unix时间戳
02)date string date(日期格式(时间戳)) 格式化一个本地时间
格式:
Y 年
m 月
d 天
H 小时
i 分钟
s 秒
注:用time(),date()函数获得都是格林威治时间,在这里使用时一定要注意调整,如何调整?
方法一,修改php.ini文件
方法二, date_default_timezone_set(PRC);
下面是所有的时区标识符:(供大家参考)
CET
CST6CDT
Cuba
EET
Egypt
Eire
EST
EST5EDT
Etc/GMT
Etc/GMT+0
Etc/GMT+1
Etc/GMT+10
Etc/GMT+11
Etc/GMT+12
Etc/GMT+2
Etc/GMT+3
Etc/GMT+4
Etc/GMT+5
Etc/GMT+6
Etc/GMT+7
Etc/GMT+8
Etc/GMT+9
Etc/GMT-0
Etc/GMT-1
Etc/GMT-10
Etc/GMT-11
Etc/GMT-12
Etc/GMT-13
Etc/GMT-14
Etc/GMT-2
Etc/GMT-3
Etc/GMT-4
Etc/GMT-5
Etc/GMT-6
Etc/GMT-7
Etc/GMT-8
Etc/GMT-9
Etc/GMT0
Etc/Greenwich
Etc/UCT
Etc/Universal
Etc/UTC
Etc/Zulu
Factory
GB
GB-Eire
GMT
GMT+0
GMT-0
GMT0
Greenwich
Hongkong
HST
Iceland
Iran
Israel
Jamaica
Japan
Kwajalein
Libya
MET
MST
MST7MDT
Navajo
NZ
NZ-CHAT
Poland
Portugal
PRC
PST8PDT
ROC
ROK
Singapore
Turkey
UCT
Universal
UTC
W-SU
WET
03)strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳
int strtotime ( string $time [, int $now = time() ] )
04)date_default_timezone_set
bool date_default_timezone_set ( string $timezone_identifier )
格式一: date_default_timezone_set("Asia/Shanghai");//临时设置北京时间
格式二:date_default_timezone_set(PRC);临时设置北京时间
扩展:修改默认时区
appserv php.ini在c:/windows/php.ini
Note:
注:自 PHP 5.1.0 起string strrev ( string $string )(此版本日期时间函数被重写了),如果时区不合法则每个对日期时间函数的调用都
产生一条 E_NOTICE 级别的错误信息,如果使用系统设定或 TZ 环境变量则还会产生 E_STRICT 级别的信息。
date_default_timezone_set = date.timezone()
3 字符串函数
01)strlen() int strlen ( string $string )
返回给定的字符串 string 的长度。
$str1 ="abcdefghijklmn";
echo strlen($str1); //结果是14,,不过这里要注意的是字符串单个字符计数是从0开始技术的,最后一个字符是13
02)strtolower — 将字符串转化为小写 string strtolower ( string $string )
03)strtoupper — 将字符串转化为大写 string strtoupper ( string $string )
04)ucfirst — 将字符串的首字母转换为大写 string ucfirst ( string $str )
05)ucwords — 将字符串中每个单词的首字母转换为大写 string ucwords ( string $str )
06)strrev— 反转字符串 string strrev ( string $string )
09)str_replace— 子字符串替换 mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
10)strpos— 查找字符串首次出现的位置 mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
返回 needle 在 haystack 中首次出现的数字位置。
找不到相应字符,输出false/空
11)substr — 返回字符串的子串 string substr ( string $string , int $start [, int $length ] )
返回提取的子字符串, 或者在失败时返回 FALSE,如果没有length,从开始位截取到最后。length必须为正整数
start 可以为负,但不报错,都要求写成整数
时间戳 : 1970.1.1.0到现在的秒数
01) time int time(void) 返回当前的unix时间戳
02)date string date(日期格式(时间戳)) 格式化一个本地时间
格式:
Y 年
m 月
d 天
H 小时
i 分钟
s 秒
注:用time(),date()函数获得都是格林威治时间,在这里使用时一定要注意调整,如何调整?
方法一,修改php.ini文件
方法二, date_default_timezone_set(PRC);
下面是所有的时区标识符:(供大家参考)
CET
CST6CDT
Cuba
EET
Egypt
Eire
EST
EST5EDT
Etc/GMT
Etc/GMT+0
Etc/GMT+1
Etc/GMT+10
Etc/GMT+11
Etc/GMT+12
Etc/GMT+2
Etc/GMT+3
Etc/GMT+4
Etc/GMT+5
Etc/GMT+6
Etc/GMT+7
Etc/GMT+8
Etc/GMT+9
Etc/GMT-0
Etc/GMT-1
Etc/GMT-10
Etc/GMT-11
Etc/GMT-12
Etc/GMT-13
Etc/GMT-14
Etc/GMT-2
Etc/GMT-3
Etc/GMT-4
Etc/GMT-5
Etc/GMT-6
Etc/GMT-7
Etc/GMT-8
Etc/GMT-9
Etc/GMT0
Etc/Greenwich
Etc/UCT
Etc/Universal
Etc/UTC
Etc/Zulu
Factory
GB
GB-Eire
GMT
GMT+0
GMT-0
GMT0
Greenwich
Hongkong
HST
Iceland
Iran
Israel
Jamaica
Japan
Kwajalein
Libya
MET
MST
MST7MDT
Navajo
NZ
NZ-CHAT
Poland
Portugal
PRC
PST8PDT
ROC
ROK
Singapore
Turkey
UCT
Universal
UTC
W-SU
WET
03)strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳
int strtotime ( string $time [, int $now = time() ] )
04)date_default_timezone_set
bool date_default_timezone_set ( string $timezone_identifier )
格式一: date_default_timezone_set("Asia/Shanghai");//临时设置北京时间
格式二:date_default_timezone_set(PRC);临时设置北京时间
扩展:修改默认时区
appserv php.ini在c:/windows/php.ini
Note:
注:自 PHP 5.1.0 起string strrev ( string $string )(此版本日期时间函数被重写了),如果时区不合法则每个对日期时间函数的调用都
产生一条 E_NOTICE 级别的错误信息,如果使用系统设定或 TZ 环境变量则还会产生 E_STRICT 级别的信息。
date_default_timezone_set = date.timezone()
3 字符串函数
01)strlen() int strlen ( string $string )
返回给定的字符串 string 的长度。
$str1 ="abcdefghijklmn";
echo strlen($str1); //结果是14,,不过这里要注意的是字符串单个字符计数是从0开始技术的,最后一个字符是13
02)strtolower — 将字符串转化为小写 string strtolower ( string $string )
03)strtoupper — 将字符串转化为大写 string strtoupper ( string $string )
04)ucfirst — 将字符串的首字母转换为大写 string ucfirst ( string $str )
05)ucwords — 将字符串中每个单词的首字母转换为大写 string ucwords ( string $str )
06)strrev— 反转字符串 string strrev ( string $string )
07)trim — 去除字符串首尾处的空白字符(或者其他字符)string trim ( string $str [, string $charlist = " \t\n\r\0\x0B" ] )
09)str_replace— 子字符串替换 mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
10)strpos— 查找字符串首次出现的位置 mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )
返回 needle 在 haystack 中首次出现的数字位置。
找不到相应字符,输出false/空
11)substr — 返回字符串的子串 string substr ( string $string , int $start [, int $length ] )
返回提取的子字符串, 或者在失败时返回 FALSE,如果没有length,从开始位截取到最后。length必须为正整数
start 可以为负,但不报错,都要求写成整数
0 0
- php学习06-02
- php学习-06常量
- php学习笔记06
- PHP学习笔记 06
- php学习笔记-02
- php学习-02变量
- php 学习02
- php学习笔记02
- PHP学习笔记 02
- PHP学习02----PHP扩展库
- 学习PHP php数据类型
- 【PHP学习】PHP第一步
- PHP学习 --mysql+php
- php学习 left.php
- [PHP学习] 初识PHP
- php学习
- PHP学习
- php学习
- 程序员面试金典目录
- java中线程安全的集合
- Android学习第十一天--------Android App AllowBackup
- 【HDU 5828】Rikka with Sequence(线段树)
- 51node-1627 瞬间移动
- php学习06-02
- 工作随笔
- ThinkPad T450无线网络不可用解决笔记
- PL/SQL如何调试Oracle存储过程
- 动态数据源3之动态分库反思
- Hadoop集群之Hive安装配置
- spring boot实战一
- c++ stl栈容器stack的pop(),push()等用法介绍及头文件
- ubuntu安装sbt