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
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().
?
?
?
?

핫 AI 도구

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

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

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











많은 사용자들이 스마트 시계를 선택할 때 Huawei 브랜드를 선택하게 됩니다. 그 중 Huawei GT3pro와 GT4가 가장 인기 있는 선택입니다. 두 제품의 차이점을 궁금해하는 사용자가 많습니다. Huawei GT3pro와 GT4의 차이점은 무엇입니까? 1. 외관 GT4: 46mm와 41mm, 재질은 유리 거울 + 스테인레스 스틸 본체 + 고해상도 섬유 후면 쉘입니다. GT3pro: 46.6mm 및 42.9mm, 재질은 사파이어 유리 + 티타늄 본체/세라믹 본체 + 세라믹 백 쉘입니다. 2. 건강한 GT4: 최신 Huawei Truseen5.5+ 알고리즘을 사용하면 결과가 더 정확해집니다. GT3pro: ECG 심전도, 혈관 및 안전성 추가

C 언어에서 return의 사용법은 다음과 같습니다. 1. 반환 값 유형이 void인 함수의 경우 return 문을 사용하여 함수 실행을 조기에 종료할 수 있습니다. 2. 반환 값 유형이 void가 아닌 함수의 경우 return 문은 함수 실행을 종료하는 것입니다. 결과는 호출자에게 반환됩니다. 3. 함수 실행을 조기에 종료합니다. 함수 내부에서는 return 문을 사용하여 함수 실행을 조기에 종료할 수 있습니다. 함수가 값을 반환하지 않는 경우.

함수는 특정 기능을 포함하는 재사용 가능한 코드 블록으로, 입력 매개변수를 받아들이고 특정 작업을 수행하며 결과를 반환하는 것이 목적입니다. 코드 재사용성과 유지 관리성을 향상시키는 코드입니다.

시스템 타임스탬프를 기반으로 파일과 폴더를 자동으로 만들고 이름을 지정하는 방법을 찾고 있다면 잘 찾아오셨습니다. 이 작업을 수행하는 매우 간단한 방법이 있습니다. 생성된 폴더 또는 파일은 파일 백업 저장, 날짜 기준 파일 정렬 등 다양한 목적으로 사용될 수 있습니다. 이 기사에서는 Windows 11/10에서 자동으로 파일과 폴더를 생성하고 시스템의 타임스탬프에 따라 이름을 지정하는 방법을 매우 간단한 단계로 설명합니다. 사용된 방법은 매우 간단한 배치 스크립트입니다. 이 기사를 재미있게 읽으셨기를 바랍니다. 섹션 1: 시스템의 현재 타임스탬프를 기반으로 폴더를 자동으로 생성하고 이름을 지정하는 방법 1단계: 먼저 폴더를 생성하려는 상위 폴더로 이동한 다음,

PHP 프로그램을 사용하여 개발할 때 종종 경고나 오류 메시지가 표시됩니다. 그 중 나타날 수 있는 오류 메시지 중 하나는 다음과 같습니다. PHPWarning:date()expectsparameter2tobelong,stringgiven. 오류 메시지는 다음을 의미합니다. 함수 date()의 두 번째 매개변수는 긴 정수(long)일 것으로 예상되지만 실제로 전달되는 것은 문자열(string)입니다. 그래서 우리는

소스 코드: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}# 출력 위 코드의 출력은 간단히 결론을 내릴 수 있습니다. return은 finally 전에 실행됩니다. 바이트코드 수준에서 무슨 일이 일어나는지 살펴보겠습니다. 다음은 case1 메소드의 바이트코드 일부를 가로채서 소스 코드를 비교하여 각 명령어의 의미를 주석으로 표시합니다.

Windows 11에서 캡처 도구가 작동하지 않는 이유 문제의 근본 원인을 이해하면 올바른 솔루션을 찾는 데 도움이 될 수 있습니다. 캡처 도구가 제대로 작동하지 않는 주요 이유는 다음과 같습니다. 초점 도우미가 켜져 있습니다. 이렇게 하면 캡처 도구가 열리지 않습니다. 손상된 응용 프로그램: 캡처 도구가 실행 시 충돌하는 경우 응용 프로그램이 손상되었을 수 있습니다. 오래된 그래픽 드라이버: 호환되지 않는 드라이버가 캡처 도구를 방해할 수 있습니다. 다른 응용 프로그램의 간섭: 실행 중인 다른 응용 프로그램이 캡처 도구와 충돌할 수 있습니다. 인증서가 만료되었습니다. 업그레이드 프로세스 중 오류로 인해 이 문제가 발생할 수 있습니다. 이 문제는 대부분의 사용자에게 적합하며 특별한 기술 지식이 필요하지 않습니다. 1. Windows 및 Microsoft Store 앱 업데이트

Date 클래스의 getTime() 메소드를 사용하여 날짜를 밀리초 단위로 표현하는 방법 Java에서 Date 클래스는 날짜와 시간을 나타내는 데 사용되는 클래스입니다. 날짜 객체에 대한 정보를 조작하고 얻는 데 유용한 많은 방법을 제공합니다. 그중 getTime() 메소드는 날짜 객체의 밀리초 표현을 반환할 수 있는 Date 클래스의 중요한 메소드입니다. 다음으로 이 메서드를 사용하여 날짜의 밀리초 표현을 얻는 방법을 자세히 설명하고 해당 코드 예제를 제공합니다. 날짜 클래스 사용
