myp*_*l00 22 php time addition
我有时间:
$today = time();
$date = date('h:i:s A', strtotime($today));
Run Code Online (Sandbox Code Playgroud)
如果当前时间是"凌晨1:00:00",我如何再增加10个小时才能成为上午11:00:00?
Amb*_*ber 50
strtotime()
给你一个代表一个秒的时间的数字.要增加它,请添加要添加的相应秒数.10小时= 60*60*10 = 36000,所以......
$date = date('h:i:s A', strtotime($today)+36000); // $today is today date
Run Code Online (Sandbox Code Playgroud)
编辑:我原以为你今天有一个字符串时间 - 如果你只是使用当前时间,甚至更简单:
$date = date('h:i:s A', time()+36000); // time() returns a time in seconds already
Run Code Online (Sandbox Code Playgroud)
小智 21
$tz = new DateTimeZone('Europe/London');
$date = new DateTime($today, $tz);
$date->modify('+10 hours');
// use $date->format() to outputs the result.
Run Code Online (Sandbox Code Playgroud)
请参阅DateTime类 (PHP 5> = 5.2.0)
DateTime
OOP Style类.<?php
$date = new DateTime('1:00:00');
$date->add(new DateInterval('PT10H'));
echo $date->format('H:i:s a'); //"prints" 11:00:00 a.m
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
107117 次 |
最近记录: |