찾다
백엔드 개발PHP 튜토리얼DateFormat PHP Class (php 处置日期)

DateFormat PHP Class (php 处理日期)

代码:

<?phpclass 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) ?<p>实例:</p><pre name="code" class="php">$date = new FormatDate(time());echo $date->Day().'<br>';// 2echo $date->WeekDay().'<br>';// Tuesdayecho $date->Month().'<br>';// Augustecho $date->MonthShort().'<br>';// Augecho $date->MonthNum().'<br>';// 8echo $date->YearFull().'<br>';// 2011echo $date->Year().'<br>';// 11echo $date->MilitaryFull().'<br>';// 9:08:40echo $date->Military().'<br>';// 9:08echo $date->StandardFull().'<br>';// 9:08:40 amecho $date->Standard().'<br>';// 9:08 amecho $date->TextDate().'<br>';// August 2 2011echo $date->TextDateShort().'<br>';// Aug 2 11echo $date->NumDate().'<br>';// 8/2/2011echo $date->NumDateShort().'<br>';// 8/2/11echo $date->MonthDay().'<br>';// August 2echo $date->MonthDayShort().'<br>';// Aug 2echo $date->TimeSince(time()).'<br>';// 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 aninteger Unix timestamp that defaults to the currentlocal time if a timestamp is not given. In otherwords, it defaults to the value of time().

?

?

?

?

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
PHP : 서버 측 스크립팅 언어 소개PHP : 서버 측 스크립팅 언어 소개Apr 16, 2025 am 12:18 AM

PHP는 동적 웹 개발 및 서버 측 응용 프로그램에 사용되는 서버 측 스크립팅 언어입니다. 1.PHP는 편집이 필요하지 않으며 빠른 발전에 적합한 해석 된 언어입니다. 2. PHP 코드는 HTML에 포함되어 웹 페이지를 쉽게 개발할 수 있습니다. 3. PHP는 서버 측 로직을 처리하고 HTML 출력을 생성하며 사용자 상호 작용 및 데이터 처리를 지원합니다. 4. PHP는 데이터베이스와 상호 작용하고 프로세스 양식 제출 및 서버 측 작업을 실행할 수 있습니다.

PHP 및 웹 : 장기적인 영향 탐색PHP 및 웹 : 장기적인 영향 탐색Apr 16, 2025 am 12:17 AM

PHP는 지난 수십 년 동안 네트워크를 형성했으며 웹 개발에서 계속 중요한 역할을 할 것입니다. 1) PHP는 1994 년에 시작되었으며 MySQL과의 원활한 통합으로 인해 개발자에게 최초의 선택이되었습니다. 2) 핵심 기능에는 동적 컨텐츠 생성 및 데이터베이스와의 통합이 포함되며 웹 사이트를 실시간으로 업데이트하고 맞춤형 방식으로 표시 할 수 있습니다. 3) PHP의 광범위한 응용 및 생태계는 장기적인 영향을 미쳤지 만 버전 업데이트 및 보안 문제에 직면 해 있습니다. 4) PHP7의 출시와 같은 최근 몇 년간의 성능 향상을 통해 현대 언어와 경쟁 할 수 있습니다. 5) 앞으로 PHP는 컨테이너화 및 마이크로 서비스와 같은 새로운 도전을 다루어야하지만 유연성과 활발한 커뮤니티로 인해 적응력이 있습니다.

PHP를 사용하는 이유는 무엇입니까? 설명 된 장점과 혜택PHP를 사용하는 이유는 무엇입니까? 설명 된 장점과 혜택Apr 16, 2025 am 12:16 AM

PHP의 핵심 이점에는 학습 용이성, 강력한 웹 개발 지원, 풍부한 라이브러리 및 프레임 워크, 고성능 및 확장 성, 크로스 플랫폼 호환성 및 비용 효율성이 포함됩니다. 1) 배우고 사용하기 쉽고 초보자에게 적합합니다. 2) 웹 서버와 우수한 통합 및 여러 데이터베이스를 지원합니다. 3) Laravel과 같은 강력한 프레임 워크가 있습니다. 4) 최적화를 통해 고성능을 달성 할 수 있습니다. 5) 여러 운영 체제 지원; 6) 개발 비용을 줄이기위한 오픈 소스.

신화를 폭로 : PHP가 실제로 죽은 언어입니까?신화를 폭로 : PHP가 실제로 죽은 언어입니까?Apr 16, 2025 am 12:15 AM

PHP는 죽지 않았습니다. 1) PHP 커뮤니티는 성능 및 보안 문제를 적극적으로 해결하고 PHP7.x는 성능을 향상시킵니다. 2) PHP는 최신 웹 개발에 적합하며 대규모 웹 사이트에서 널리 사용됩니다. 3) PHP는 배우기 쉽고 서버가 잘 수행되지만 유형 시스템은 정적 언어만큼 엄격하지 않습니다. 4) PHP는 컨텐츠 관리 및 전자 상거래 분야에서 여전히 중요하며 생태계는 계속 발전하고 있습니다. 5) Opcache 및 APC를 통해 성능을 최적화하고 OOP 및 설계 패턴을 사용하여 코드 품질을 향상시킵니다.

PHP vs. Python 토론 : 어느 것이 더 낫습니까?PHP vs. Python 토론 : 어느 것이 더 낫습니까?Apr 16, 2025 am 12:03 AM

PHP와 Python에는 고유 한 장점과 단점이 있으며 선택은 프로젝트 요구 사항에 따라 다릅니다. 1) PHP는 웹 개발, 배우기 쉽고 풍부한 커뮤니티 리소스에 적합하지만 구문은 현대적이지 않으며 성능과 보안에주의를 기울여야합니다. 2) Python은 간결한 구문과 배우기 쉬운 데이터 과학 및 기계 학습에 적합하지만 실행 속도 및 메모리 관리에는 병목 현상이 있습니다.

PHP의 목적 : 동적 웹 사이트 구축PHP의 목적 : 동적 웹 사이트 구축Apr 15, 2025 am 12:18 AM

PHP는 동적 웹 사이트를 구축하는 데 사용되며 해당 핵심 기능에는 다음이 포함됩니다. 1. 데이터베이스와 연결하여 동적 컨텐츠를 생성하고 웹 페이지를 실시간으로 생성합니다. 2. 사용자 상호 작용 및 양식 제출을 처리하고 입력을 확인하고 작업에 응답합니다. 3. 개인화 된 경험을 제공하기 위해 세션 및 사용자 인증을 관리합니다. 4. 성능을 최적화하고 모범 사례를 따라 웹 사이트 효율성 및 보안을 개선하십시오.

PHP : 데이터베이스 및 서버 측 로직 처리PHP : 데이터베이스 및 서버 측 로직 처리Apr 15, 2025 am 12:15 AM

PHP는 MySQLI 및 PDO 확장 기능을 사용하여 데이터베이스 작업 및 서버 측 로직 프로세싱에서 상호 작용하고 세션 관리와 같은 기능을 통해 서버 측로 로직을 처리합니다. 1) MySQLI 또는 PDO를 사용하여 데이터베이스에 연결하고 SQL 쿼리를 실행하십시오. 2) 세션 관리 및 기타 기능을 통해 HTTP 요청 및 사용자 상태를 처리합니다. 3) 트랜잭션을 사용하여 데이터베이스 작업의 원자력을 보장하십시오. 4) SQL 주입 방지, 디버깅을 위해 예외 처리 및 폐쇄 연결을 사용하십시오. 5) 인덱싱 및 캐시를 통해 성능을 최적화하고, 읽을 수있는 코드를 작성하고, 오류 처리를 수행하십시오.

PHP에서 SQL 주입을 어떻게 방지합니까? (준비된 진술, pdo)PHP에서 SQL 주입을 어떻게 방지합니까? (준비된 진술, pdo)Apr 15, 2025 am 12:15 AM

PHP에서 전처리 문과 PDO를 사용하면 SQL 주입 공격을 효과적으로 방지 할 수 있습니다. 1) PDO를 사용하여 데이터베이스에 연결하고 오류 모드를 설정하십시오. 2) 준비 방법을 통해 전처리 명세서를 작성하고 자리 표시자를 사용하여 데이터를 전달하고 방법을 실행하십시오. 3) 쿼리 결과를 처리하고 코드의 보안 및 성능을 보장합니다.

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
1 몇 달 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 채팅 명령 및 사용 방법
1 몇 달 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

WebStorm Mac 버전

WebStorm Mac 버전

유용한 JavaScript 개발 도구

에디트플러스 중국어 크랙 버전

에디트플러스 중국어 크랙 버전

작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

Dreamweaver Mac版

Dreamweaver Mac版

시각적 웹 개발 도구

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.