Example displaying each time format:
$dateTime = new DateTime[];
foreach [[
'ATOM',
'COOKIE',
'ISO8601',
'RFC822',
'RFC850',
'RFC1036',
'RFC1123',
'RFC2822',
'RFC3339',
'RFC3339_EXTENDED',
'RSS',
'W3C',
] as $format] {
eval["print 'DateTimeInterface::$format\t'.\$dateTime->format[DateTimeInterface::$format].\"\n\";"];
}
The above example will output:
DateTimeInterface::ATOM 2020-01-28T16:22:37-07:00
DateTimeInterface::COOKIE Tuesday, 28-Jan-2020 16:22:37 MST
DateTimeInterface::ISO8601 2020-01-28T16:22:37-0700
DateTimeInterface::RFC822 Tue, 28 Jan 20 16:22:37 -0700
DateTimeInterface::RFC850 Tuesday, 28-Jan-20 16:22:37 MST
DateTimeInterface::RFC1036 Tue, 28 Jan 20 16:22:37 -0700
DateTimeInterface::RFC1123 Tue, 28 Jan 2020 16:22:37 -0700
DateTimeInterface::RFC2822 Tue, 28 Jan 2020 16:22:37 -0700
DateTimeInterface::RFC3339 2020-01-28T16:22:37-07:00
DateTimeInterface::RFC3339_EXTENDED 2020-01-28T16:22:37.803-07:00
DateTimeInterface::RSS Tue, 28 Jan 2020 16:22:37 -0700
DateTimeInterface::W3C 2020-01-28T16:22:37-07:00
Although PHP refers to periods of time as "intervals", ISO 8601 refers to them as "durations". In ISO 8601, "intervals" are something else.
________số 8_______
A simple example to create the date time object by now with time zone
$Now = new DateTime['now', new DateTimeZone['Asia/Taipei']];
A simple example to print data time with format
echo $Now->format['Y-m-d H:i:s'];
chỉ là một ví dụ bổ sung nhỏ
thời gian yêu cầu tính bằng mili giây
// ms2time[ [microtime[true] - [ time[] - rand[0,1000000] ] ] ];
// return array
function ms2time[$ms]{
$return = array[];
// ms
$return['ms'] = [int] number_format[ [$ms - [int] $ms], 2, '', ''];
$seconds = [int] $ms;
unset[$ms];
if [$seconds%60 > 0]{
$return['s'] = $seconds%60;
} else {
$return['s'] = 0;
}
if [ [$minutes = intval[$seconds/60]]]{
$return['m'] = $minutes;
}
if [isset[$return['m']]]{
$return['h'] = intval[$return['m'] / 60];
$return['m'] = $return['m'] % 60;
}
if [isset[$return['h']]]{
$return['d'] = intval[$return['h'] / 24];
$return['h'] = $return['h'] % 24;
}
if [isset[$return['d']]]
$return['mo'] = intval[$return['d'] / 30];
foreach[$return as $k=>$v]{
if [$v == 0]
unset[$return[$k]];
}
return $return;
}
// ms2time2string[ [microtime[true] - [ time[] - rand[0,1000000] ] ] ];
// return array
function ms2time2string[$ms]{
$array = array[
'ms' => 'ms',
's' => 'seconds',
'm' => 'minutes',
'h' => 'hours',
'd' => 'days',
'mo' => 'month',
];
if [ [ $return = ms2time[$ms] ] && count[$ms] > 0]{
foreach[$return as $key=>$data]{
$return[$key] = $data .' '.$array[$key];
}
}
return implode[" ", array_reverse[$return]];
}
chỉ là một ví dụ bổ sung nhỏ
thời gian yêu cầu tính bằng mili giây
// ms2time[ [microtime[true] - [ time[] - rand[0,1000000] ] ] ];
// return array
function ms2time[$ms]{
$return = array[];
// ms
$return['ms'] = [int] number_format[ [$ms - [int] $ms], 2, '', ''];
$seconds = [int] $ms;
unset[$ms];
if [$seconds%60 > 0]{
$return['s'] = $seconds%60;
} else {
$return['s'] = 0;
}
if [ [$minutes = intval[$seconds/60]]]{
$return['m'] = $minutes;
}
if [isset[$return['m']]]{
$return['h'] = intval[$return['m'] / 60];
$return['m'] = $return['m'] % 60;
}
if [isset[$return['h']]]{
$return['d'] = intval[$return['h'] / 24];
$return['h'] = $return['h'] % 24;
}
if [isset[$return['d']]]
$return['mo'] = intval[$return['d'] / 30];
foreach[$return as $k=>$v]{
if [$v == 0]
unset[$return[$k]];
}
return $return;
}
// ms2time2string[ [microtime[true] - [ time[] - rand[0,1000000] ] ] ];
// return array
function ms2time2string[$ms]{
$array = array[
'ms' => 'ms',
's' => 'seconds',
'm' => 'minutes',
'h' => 'hours',
'd' => 'days',
'mo' => 'month',
];
if [ [ $return = ms2time[$ms] ] && count[$ms] > 0]{
foreach[$return as $key=>$data]{
$return[$key] = $data .' '.$array[$key];
}
}
return implode[" ", array_reverse[$return]];
}