php 日期format不要零_DateFormat PHP Class (php 处置日期)
DateFormat PHP Class (php 处理日期)
代码:
class FormatDate
{
var $theTime;
function FormatDate($string)
{
//Set constructor
$this->theTime = $string;
}
//Returns numerical day
function Day() {return date("j", $this->theTime); }
//Returns weekday
function WeekDay() { return date("l", $this->theTime); }
//Returns full month
function Month(){return date("F", $this->theTime); }
//Returns short-hand month
function MonthShort() { return date("M", $this->theTime); }
//Numeric for month
function MonthNum() { return date("n", $this->theTime); }
//Full 4 digit year
function YearFull() { return date("Y", $this->theTime); }
//Short 2 digit year
function Year() { return date("y", $this->theTime); }
//24 Hr with Seconds
function MilitaryFull(){return date("G:i:s", $this->theTime); }
//24 Hr without Seconds
function Military(){return date("G:i", $this->theTime); }
//Standard with seconds
function StandardFull(){return date("g:i:s a", $this->theTime); }
//Standard without seconds
function Standard(){return date("g:i a", $this->theTime); }
//Date & Month & Year Full
function TextDate(){$string = $this->Month()." ".$this->Day()." ".$this->YearFull();
return $string;
}
//Date & Month & Year Shorthand
function TextDateShort(){$string = $this->MonthShort()." ".$this->Day()." ".$this->Year();
return $string;
}
//Numerical Date & Month & Year
function NumDate(){$string = $this->MonthNum()."/".$this->Day()."/".$this->YearFull();
return $string;
}
//Numerical Date & Month & Year Shorthand
function NumDateShort(){$string = $this->MonthNum()."/".$this->Day()."/".$this->Year();
return $string;
}
//Month & Day Full
function MonthDay(){$string = $this->Month()." ".$this->Day();
return $string;
}
//Month & Day Short
function MonthDayShort(){$string = $this->MonthShort()." ".$this->Day();
return $string;
}
function TimeSince($old_stamp) {
$difference = $this->theTime - $old_stamp;
$loop = true;
while($loop) {
if(round($difference/3153600, 2) >= 1) { return "Over a year..."; }
elseif(round($difference/2592000, 2) >= 2) { return "Over ".round($difference/2592000,0)." months ago..."; }
elseif(round($difference/2592000, 2) >= 1.20) { return "Over a month ago..."; }
elseif(round($difference/604800, 2) >= 2) { return "Over ".round($difference/604800,0)." weeks ago.."; }
elseif(round($difference/604800, 2) >= 1.20) { return "Over a week ago.."; }
elseif(round($difference/86400, 2) >= 1.9) { return "Over a few days ago...";}
elseif(round($difference/3600, 2) >= 3) { return "Just a few hours ago.."; }
elseif(round($difference/3600, 2) >= 8) { return "About half a day ago..."; }
elseif(round($difference/3600, 2) < 1) { return "Less than an hour ago..."; }
elseif(round($difference/86400, 2) < 1.9) { return "About a day ago..."; }
elseif(round($difference/86400, 2) < 6 ) { return "Less than a week ago..."; }
elseif(round($difference/604800, 2) < 1.20) { return "About a week ago.."; }
elseif(round($difference/2592000, 2) < 1.20) { return "About a month ago..."; }
else{ return "Error"; }
$loop = false;
}
}
}
实例:
$date = new FormatDate(time());
echo $date->Day().'
';
// 2
echo $date->WeekDay().'
';
// Tuesday
echo $date->Month().'
';
// August
echo $date->MonthShort().'
';
// Aug
echo $date->MonthNum().'
';
// 8
echo $date->YearFull().'
';
// 2011
echo $date->Year().'
';
// 11
echo $date->MilitaryFull().'
';
// 9:08:40
echo $date->Military().'
';
// 9:08
echo $date->StandardFull().'
';
// 9:08:40 am
echo $date->Standard().'
';
// 9:08 am
echo $date->TextDate().'
';
// August 2 2011
echo $date->TextDateShort().'
';
// Aug 2 11
echo $date->NumDate().'
';
// 8/2/2011
echo $date->NumDateShort().'
';
// 8/2/11
echo $date->MonthDay().'
';
// August 2
echo $date->MonthDayShort().'
';
// Aug 2
echo $date->TimeSince(time()).'
';
// Less than an hour ago...
DateFormat Class Documentation
Initialize Class
$date = new FormatDate(time());
Numerical Day
$date->Day();
Text Day
$date->WeekDay();
Month (Full)
$date->Month();
Month (Short)
$date->MonthShort();
Month (Numerical)
$date->MonthNum();
Year (Full)
$date->YearFull();
Year (Short)
$date->Year();
Military (Seconds)
$date->MilitaryFull();
Military (No seconds)
$date->Military();
Standard (Full)
$date->StandardFull();
Standard
$date->Standard();
Text Date (Full)
$date->TextDate();
Text Date (Short)
$date->TextDateShort();
Numerical Date (Full)
$date->NumDate();
Numerical Date (Short)
$date->NumDateShort();
Month and Day (Full)
$date->MonthDay();
Month and Day (Short)
$date->MonthDayShort();
Time Since
$date->TimeSince($timestamp);
格式: http://php.net/manual/en/function.date.php
format
character
Description
Example returned values
Day
---
---
d
Day of the month, 2 digits with leading zeros
01
to 31
D
A textual representation of a day, three letters
Mon
through Sun
j
Day of the month without leading zeros
1
to 31
l
(lowercase 'L')
A full textual representation of the day of the week
Sunday
through Saturday
N
ISO-8601 numeric representation of the day of the week (added in
PHP 5.1.0)
1
(for Monday) through 7
(for Sunday)
S
English ordinal suffix for the day of the month, 2 characters
st
, nd
, rd
or
th
. Works well with j
w
Numeric representation of the day of the week
0
(for Sunday) through 6
(for Saturday)
z
The day of the year (starting from 0)
0
through 365
Week
---
---
W
ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)
Example: 42
(the 42nd week in the year)
Month
---
---
F
A full textual representation of a month, such as January or March
January
through December
m
Numeric representation of a month, with leading zeros
01
through 12
M
A short textual representation of a month, three letters
Jan
through Dec
n
Numeric representation of a month, without leading zeros
1
through 12
t
Number of days in the given month
28
through 31
Year
---
---
L
Whether it's a leap year
1
if it is a leap year, 0
otherwise.
o
ISO-8601 year number. This has the same value as
Y
, except that if the ISO week number
(W
) belongs to the previous or next year, that year
is used instead. (added in PHP 5.1.0)
Examples: 1999
or 2003
Y
A full numeric representation of a year, 4 digits
Examples: 1999
or 2003
y
A two digit representation of a year
Examples: 99
or 03
Time
---
---
a
Lowercase Ante meridiem and Post meridiem
am
or pm
A
Uppercase Ante meridiem and Post meridiem
AM
or PM
B
Swatch Internet time
000
through 999
g
12-hour format of an hour without leading zeros
1
through 12
G
24-hour format of an hour without leading zeros
0
through 23
h
12-hour format of an hour with leading zeros
01
through 12
H
24-hour format of an hour with leading zeros
00
through 23
i
Minutes with leading zeros
00
to 59
s
Seconds, with leading zeros
00
through 59
u
Microseconds (added in PHP 5.2.2)
Example: 654321
Timezone
---
---
e
Timezone identifier (added in PHP 5.1.0)
Examples: UTC
, GMT
, Atlantic/Azores
I
(capital i)
Whether or not the date is in daylight saving time
1
if Daylight Saving Time, 0
otherwise.
O
Difference to Greenwich time (GMT) in hours
Example: +0200
P
Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)
Example: +02:00
T
Timezone abbreviation
Examples: EST
, MDT
...
Z
Timezone offset in seconds. The offset for timezones west of UTC is always
negative, and for those east of UTC is always positive.
-43200
through 50400
Full Date/Time
---
---
c
ISO 8601 date (added in PHP 5)
2004-02-12T15:19:21+00:00
r
» RFC 2822
formatted date
Example: Thu, 21 Dec 2000 16:01:07 +0200
U
Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
See also time()
Unrecognized characters in the format string will be printed
as-is. The Z
format will always return
0
when using gmdate()
.
Note
:
Since this function only accepts integer
timestamps the
u
format character is only useful when using the
date_format()
function with user based timestamps
created with date_create()
.
timestamp
The optional timestamp
parameter is an
integer
Unix timestamp that defaults to the current
local time if a timestamp
is not given. In other
words, it defaults to the value of time()
.
php 日期format不要零_DateFormat PHP Class (php 处置日期)相关推荐
- php 日期format不要零_PHP格式化日期用法代码,包括前导零示例
PHP格式化日期用法代码,包括前导零示例: format 字符 说明 返回值例子 d 月份中的第几天,有前导零的 2 位数字 01 到 31 D 星期中的第几天,文本表示,3 个字母 Mon 到 Su ...
- 【零基础学Java】—Java 日期时间(三十二)
[零基础学Java]-Java 日期时间(三十二) DateFormat 是日期/时间格式化子类的抽象类,它以语言无关的方式格式化和分析日期或时间. 日期/时间格式化子类(如SimpleDateFor ...
- mysql 去掉日期.0_简单介绍MySQL数据库中日期中包含零值的问题
下面小编就为大家带来一篇浅谈MySQL数据库中日期中包含零值的问题.小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧 默认情况下MySQL是可以接受在日期中插入0值,对于现 ...
- 【零基础学Java】—Java 日期时间(三十一)
[零基础学Java]-Java 日期时间(三十一) java.util.Date:表示日期和时间的类 类Date表示特定的瞬间,精确到毫秒 毫秒:千分之一秒,1000毫秒=1秒 特定的时间:一个时间点 ...
- 零基础带你学习MySQL—日期函数(十五)
零基础带你学习MySQL-日期函数(十五) 一.CURRENT_DATE ( ) 当前日期 二.CURRENT_TIME() 当前时间 三.CURRENT_TIMESTAMP()当前时间戳 四.练习
- java 日期format字符串 dd 与 DD ,yy与YY,mm与MM
java 日期format字符串 dd 与 DD ,yy与YY,mm与MM 小写d是指月中的日号(1-31) Date now = new Date();System.out.println(Date ...
- sql server 中获取前一天日期_图解SQL面试题:如何比较日期数据?
[题目] 下面是某公司每天的营业额,表名为"日销"."日期"这一列的数据类型是日期类型(date). 请找出所有比前一天(昨天)营业额更高的数据.(前一天的意 ...
- java日期算前一天_java 根据系统日期获取前一天、后一天时间(根据初始日期推算出期望(向前/向后)日期)...
1.情景展示 java 根据系统当前日期获取前一天日期.后一天日期,或者根据初始日期推算出期望(向前/向后)日期. 2.解决方案 导包 import java.text.ParseException; ...
- mysql以下日期函数正确的_[数据库]MYSQL基础03(日期函数)
[数据库]MYSQL基础03(日期函数) 0 2015-10-29 01:00:09 工作中对日期的处理是经常遇到的,需求可能多种多样,因此重点介绍. 1.获取当前日期select NOW()-- 结 ...
最新文章
- 抽象工厂模式AbstractFactory
- PgSQL · 特性分析 · full page write 机制
- MATLAB机器学习系列-8 极限学习机(Extreme Learning Machine, ELM)原理及其代码实现
- java 向上舍入_介绍Java的大数类(BigDecimal)和八种舍入模式
- CSS浮动(float)属性学习经验分享
- java 线程同步的list_java线程生产者与消费者实例(使用List实现同步)
- rmi 反序列化漏洞_写一个rmi反序列化工具
- 百度语音识别最新资讯
- 数据中心的重要服务器如何保护?
- 【自然语言处理】【知识图谱】知识图谱表示学习(一):TransE、TransH、TransR、CTransR、TransD
- [Elasticsearch] 多字段搜索 (五) - 以字段为中心的查询
- 15个搞笑的程序员段子
- wps下载的简历无法删除空白页
- 你看到的都是错的!——虚拟化技术的真相
- 英语学习之沪江整理 20141101
- 如何让百度、Google、Yahoo等搜索引擎巨头收录你的网站
- 程序员崩溃了!想拿的年终奖怎么说黄就黄?!
- 如何配置java环境变量?
- TEST1笔记 200408
- android crash存储位置,在Android手机上保存Crash Log