国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 php手冊(cè) PHP中time(),date(),mktime()區(qū)別介紹

PHP中time(),date(),mktime()區(qū)別介紹

Jun 06, 2016 pm 08:27 PM
date mktime time

PHP :time(),date(),mktime()日期與時(shí)間函數(shù)庫(kù),經(jīng)常會(huì)忘卻掉,這里收藏下, 方便需要的朋友

checkdate : 驗(yàn)證日期的正確性。
date : 將服務(wù)器的時(shí)間格式化。
strftime : 將服務(wù)器的時(shí)間本地格式化。
getdate : 獲得時(shí)間及日期信息。
gettimeofday : 取得目前時(shí)間。
gmdate : 取得目前與 GMT 差后的時(shí)間。
easter_date : 計(jì)算復(fù)活節(jié)日期。
easter_days : 計(jì)算復(fù)活節(jié)與三月廿一日之間日期數(shù)。
mktime : 取得 UNIX 時(shí)間戳記。
gmmktime : 取得 UNIX 時(shí)間戳記的格林威治時(shí)間。
time : 取得目前時(shí)間的 UNIX 時(shí)間戳記。
microtime : 取得目前時(shí)間的 UNIX 時(shí)間戳記的百萬(wàn)分之一秒值。

  checkdate 驗(yàn)證日期的正確性。

語(yǔ)法: int checkdate(int month, int day, int year);
返回值: 整數(shù)
函數(shù)種類: 時(shí)間日期
內(nèi)容說(shuō)明 若日期是有效的則返回 true,若日期有問(wèn)題,則返回 false。本函數(shù)可以用來(lái)檢查日期是否有效。有效范圍如下:
年 為 0 至 32767 年
月 為 1 至 12 月
日 則隨著月份及閏年變化

date 將服務(wù)器的時(shí)間格式化。

語(yǔ)法: string date(string format, int [timestamp]);
返回值: 字符串
函數(shù)種類: 時(shí)間日期
內(nèi)容說(shuō)明返回值的?字符串依配置的格式來(lái)決定。若有傳入時(shí)間戳記值,則將時(shí)間戳記格式化返回;若無(wú)傳入時(shí)間戳記值,則將目前服務(wù)器的時(shí)間格式化返回。要將日期轉(zhuǎn)為其它的語(yǔ)系格式,應(yīng)使用setlocale() 及 strftime() 二個(gè)函數(shù)。字符串格式化的選項(xiàng)如下:
a - "am" 或是 "pm"
A - "AM" 或是 "PM"
d - 幾日,二位數(shù)字,若不足二位則前面補(bǔ)零; 如: "01" 至 "31"
D - 星期幾,三個(gè)英文字母; 如: "Fri"
F - 月份,英文全名; 如: "January"
h - 12 小時(shí)制的小時(shí); 如: "01" 至 "12"
H - 24 小時(shí)制的小時(shí); 如: "00" 至 "23"
g - 12 小時(shí)制的小時(shí),不足二位不補(bǔ)零; 如: "1" 至 12"
G - 24 小時(shí)制的小時(shí),不足二位不補(bǔ)零; 如: "0" 至 "23"
i - 分鐘; 如: "00" 至 "59"
j - 幾日,二位數(shù)字,若不足二位不補(bǔ)零; 如: "1" 至 "31"
l - 星期幾,英文全名; 如: "Friday"
m - 月份,二位數(shù)字,若不足二位則在前面補(bǔ)零; 如: "01" 至 "12"
n - 月份,二位數(shù)字,若不足二位則不補(bǔ)零; 如: "1" 至 "12"
M - 月份,三個(gè)英文字母; 如: "Jan"
s - 秒; 如: "00" 至 "59"
S - 字尾加英文序數(shù),二個(gè)英文字母; 如: "th","nd"
t - 指定月份的天數(shù); 如: "28" 至 "31"
U - 總秒數(shù)
w - 數(shù)字型的星期幾,如: "0" (星期日) 至 "6" (星期六)
Y - 年,四位數(shù)字; 如: "1999"
y - 年,二位數(shù)字; 如: "99"
z - 一年中的第幾天; 如: "0" 至 "365"
其它不在上列的字符則直接列出該字符。

使用范例,

范例一:

復(fù)制代碼 代碼如下:



print(date( "l dS of F Y h:i:s A" ));
print("July 1, 2000 is on a " . date("l", mktime(0,0,0,7,1,2000)));
?>

  范例二:

復(fù)制代碼 代碼如下:



$tomorrow = mktime(0,0,0,date("m") ,date("d")+1,date("Y"));
$lastmonth = mktime(0,0,0,date("m")-1,date("d"), date("Y"));
$nextyear = mktime(0,0,0,date("m"), date("d", date("Y")+1);
?>

參考 gmdate() mktime()
strftime 將服務(wù)器的時(shí)間本地格式化。
語(yǔ)法: string strftime(string format, int [timestamp]);
返回值: 字符串
函數(shù)種類: 時(shí)間日期
內(nèi)容說(shuō)明返回值的字符串依配置的格式來(lái)決定。若有傳入時(shí)間戳記值,則將時(shí)間戳記格式化返回;若無(wú)傳入時(shí)間戳記值,則將目前服務(wù)器的時(shí)間本地格式化返回。月份或者星期名稱隨著本地語(yǔ)系配置 setlocale() 的不同而改變。
返回的字符串可以依下列的格式而定:
%a 星期幾的縮寫。
%A 星期幾的全名。
%b 月份名稱的縮寫。
%B 月份名稱的全名。
%c 本地端日期時(shí)間較佳表示字符串。
%d 用數(shù)字表示本月的第幾天 (范圍為 00 至 31)。
%H 用 24 小時(shí)制數(shù)字表示小時(shí)數(shù) (范圍為 00 至 23)。
%I 用 12 小時(shí)制數(shù)字表示小時(shí)數(shù) (范圍為 01 至 12)。
%j 以數(shù)字表示當(dāng)年度的第幾天 (范圍為 001 至 366)。
%m 月份的數(shù)字 (范圍由 1 至 12)。
%M 分鐘。
%p 以 'AM' 或 'PM' 表示本地端時(shí)間。
%S 秒數(shù)。
%U 數(shù)字表示為本年度的第幾周,第一個(gè)星期由第一個(gè)周日開(kāi)始。
%W 數(shù)字表示為本年度的第幾周,第一個(gè)星期由第一個(gè)周一開(kāi)始。
%w 用數(shù)字表示本周的第幾天 ( 0 為周日)。
%x 不含時(shí)間的日期表示法。
%X 不含日期的時(shí)間表示法。
%y 二位數(shù)字表示年份 (范圍由 00 至 99)。
%Y 完整的年份數(shù)字表示,即四位數(shù)。
%Z 時(shí)區(qū)或名稱縮寫。
%% % 字符。

使用范例

復(fù)制代碼 代碼如下:


setlocale ("LC_TIME", "C");
print(strftime("%A in Finnish is "));
setlocale ("LC_TIME", "fi");
print(strftime("%A, in French "));
setlocale ("LC_TIME", "fr");
print(strftime("%A and in German "));
setlocale ("LC_TIME", "de");
print(strftime("%A.n"));
?>

參考 setlocale() mktime()
getdate 獲得時(shí)間及日期信息。
語(yǔ)法: array getdate(int timestamp);
返回值: 數(shù)組
函數(shù)種類: 時(shí)間日期
內(nèi)容說(shuō)明 返回?cái)?shù)組的元素包括下列的項(xiàng)目:
"seconds" - 秒
"minutes" - 分
"hours" - 時(shí)
"mday" - 當(dāng)月的第幾天
"wday" - 當(dāng)周的第幾天數(shù)字
"mon" - 月份數(shù)字
"year" - 年,數(shù)字
"yday" - 當(dāng)年的第幾天數(shù)字; 如: "299"
"weekday" - 星期幾全名; 如: "Friday"
"month" - 月份全名; 如: "January"
gettimeofday 取得目前時(shí)間。
語(yǔ)法: array gettimeofday(void);
返回值: 數(shù)組
函數(shù)種類: 時(shí)間日期
內(nèi)容說(shuō)明 返回?cái)?shù)組的元素包括下列的項(xiàng)目:
"sec" - 秒
"usec" - 百萬(wàn)分之一秒
"minuteswest" - 格林威治時(shí)間的分
"dsttime" - 目的的時(shí)區(qū)
gmdate 取得目前與 GMT 差后的時(shí)間。
語(yǔ)法: string gmdate(string format, int timestamp);
返回值: 字符串
函數(shù)種類: 時(shí)間日期
內(nèi)容說(shuō)明 本函數(shù)與 date() 函數(shù)相似,不同的是本函數(shù)返回與格林威治標(biāo)準(zhǔn)時(shí)間 (Greenwich Mean Time, GMT) 時(shí)間差后的時(shí)間

使用范例

復(fù)制代碼 代碼如下:

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
How to create and name a file/folder based on current timestamp How to create and name a file/folder based on current timestamp Apr 27, 2023 pm 11:07 PM

If you're looking for a way to automatically create and name files and folders based on system timestamps, you've come to the right place. There is a super simple way to accomplish this task. The created folders or files can then be used for various purposes such as storing file backups, sorting files based on date, etc. In this article, we will explain in some very simple steps how to automatically create files and folders in Windows 11/10 and name them according to the system’s timestamp. The method used is a batch script, which is very simple. Hope you enjoyed reading this article. Section 1: How to automatically create and name a folder based on the current timestamp of the system Step 1: First, navigate to the parent folder where you want to create the folder,

PHP Warning: date() expects parameter 2 to be long, string given solution PHP Warning: date() expects parameter 2 to be long, string given solution Jun 22, 2023 pm 08:03 PM

When developing using PHP programs, you often encounter some warning or error messages. Among them, one error message that may appear is: PHPWarning:date()expectsparameter2tobelong,stringgiven. The error message means: the second parameter of the function date() is expected to be a long integer (long), but what is actually passed to it is a string (string). So, we

How to get the millisecond representation of a date using the getTime() method of the Date class How to get the millisecond representation of a date using the getTime() method of the Date class Jul 24, 2023 am 11:42 AM

How to get millisecond representation of date using getTime() method of Date class In Java, Date class is a class used to represent date and time. It provides many useful methods to manipulate and obtain information about date objects. Among them, the getTime() method is an important method in the Date class, which can return the millisecond representation of the date object. Next, we will detail how to use this method to obtain the millisecond representation of a date, and provide corresponding code examples. Using the Date class

Introduction to methods and usage of using Date and SimpleDateFormat classes to process time in Java Introduction to methods and usage of using Date and SimpleDateFormat classes to process time in Java Apr 21, 2023 pm 03:01 PM

1. Introduction The Date class in the java.util package represents a specific time, accurate to milliseconds. If we want to use our Date class, then we must introduce our Date class. Writing the year directly into the Date class will not produce the correct result. Because Date in Java is calculated from 1900, so as long as you fill in the first parameter with the number of years since 1900, you will get the year you want. The month needs to be subtracted by 1, and the day can be inserted directly. This method is rarely used, and the second method is commonly used. This method is to convert a string that conforms to a specific format, such as yyyy-MM-dd, into Date type data. First, define an object of Date type Date

Monotonic clock processing of time package Monotonic clock processing of time package Aug 04, 2023 pm 05:45 PM

Today we are mainly going to take a look at the time application method of golang time package. The general rule between the two is that "wall time" is used to tell time, and "monotonic clock" is used to measure time; there are other clock processing methods.

What are the options for calendar and date libraries in Python? What are the options for calendar and date libraries in Python? Oct 21, 2023 am 09:22 AM

There are many excellent calendar libraries and date libraries in Python for us to use. These libraries can help us handle date and calendar related operations. Next, I will introduce you to several common choices and provide corresponding code examples. Datetime library: Datetime is Python's built-in date and time processing module. It provides many date and time related classes and methods, which can be used to process dates, times, time differences and other operations. Sample code: importdatetime#Get the current date

How to solve the problem of springboot configuring date field to return timestamp How to solve the problem of springboot configuring date field to return timestamp May 20, 2023 am 11:16 AM

I encountered a problem. After springboot was upgraded to 2.0, the date found from the database was received using Date and finally returned directly to the front end. It can be displayed normally in the yyyy-MM-ddHH:mm:ss format in Google Chrome. However, the date displayed in the IE browser is "garbled" because the springboot1.x version returns a timestamp in the Date field by default, and Google and IE will automatically convert the timestamp into yyyy-MM-ddHH:mm:ss ;After springboot2.0, spring will automatically convert the Date field into a UTC string (without configuration), so date needs to be converted into a timestamp or y

How to use Stringbuild, Date and Calendar classes in Java How to use Stringbuild, Date and Calendar classes in Java May 22, 2023 pm 04:52 PM

Stringbuild class Since the object content of the String class cannot be changed, a new String object will be constructed every time it is spliced, which is time-consuming and wastes memory space. At this time, you need to solve this problem through the StringBuild class provided by Java. StringBuilder is also called a variable character sequence. , it is a string buffer similar to String, which can be regarded as a container. Many strings can be held in the container. Variable means that the content in the StringBuilder object is variable. The construction method publicStringBuilder(): creates an empty buffer publicStringBuilder(Stringsr

See all articles