分享一段php获取任意时间的前一天代码

<?php
/**
 * 获取给定日期的前一天
 * @param string $date
 * @return string $yesterday
 */
function getYesterday($date)
{
    if(empty($date))
    {
        $yesterday = date("Y-m-d",strtotime("-1 day"));
    }else{
        $arr = explode('-', $date);
        $year = $arr[0];
        $month = $arr[1];
        $day = $arr[2];
        $unixtime = mktime(0,0,0,$month,$day,$year)-86400;
        $yesterday = date('Y-m-d',$unixtime);
    }
    return $yesterday;
}

时间: 2024-08-01 10:09:08

分享一段php获取任意时间的前一天代码的相关文章

vbs获取当前时间日期的代码

vbs获取当前时间日期的代码,文章来源:脚本学堂. 获取当前日期方法一: Currentdate1=date()msgbox Currentdate1 获取当前日期方法二:Currentdate2=year(Now)&"-"&Month(Now)&"-"&day(Now)msgbox Currentdate2 获取当前时间:CurrentTime=Hour(Now)&":"&Minute(Now)&

js 的date的format时间,获取当前时间,前一天的日期

Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds()

mysql获取当前时间,前一天,后一天

负责的项目中,使用的是mysql数据库,页面上要显示当天所注册人数的数量,获取当前的年月日,我使用的是 CURDATE(), 错误的sql语句 eg:SELECT COUNT(*) FROM USER WHERE registerDate >= CURDATE() AND registerDate < CURDATE()+1; 虽然 获取到的数量在测试环境中是正确的,但在发布到线上的时候,发现有的时候数据是查询不到,数量为0,因此,就上网查询是不是CURDATE()+1不规范,发现mysql官

nodejs 模块moment格式化时间,获取当前时间的前一天时间

var moment = require('moment'); moment.locale('zh-cn'); var today = {}; var _today = moment(); today.year = _today.format('yyyy'); /*现在的年*/ today.date = _today.format('YYYY-MM-DD'); /*现在的时间*/ today.yesterday = _today.subtract(1, 'days').format('YYYY-

Easyui获取上个月最后一天的日期,以及获取当前时间的前一天日期

//获取上一个月最后一天的日期 lastDate = function(date){ var day = date.getDate() > 9?(date.getDate()-1):"0" + (date.getDate()-1); var month = (date.getMonth() + 1) > 9?(date.getMonth() + 1):"0"+(date.getMonth() + 1); return date.getFullYear()

JSjs获取当前时间的前一天/后一天(昨天/明天)

Date curDate = new Date(); var preDate = new Date(curDate.getTime() - 24*60*60*1000); //前一天 var nextDate = new Date(curDate.getTime() + 24*60*60*1000); //后一天 在WdatePicker中全面实行的方法 <input class="Wdate" type="text" id="date_no&quo

获取本地时间时,关于时间的显示格式问题

1.获取本地时间的相关代码: NSDateFormatter* formatter = [[NSDateFormatter alloc]init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString * date = [formatter stringFromDate:[NSDate date]]; NSLog(@"date = %@",date); 在显示时间的时候,如果表示小时的H为大写,则时间

c#获取网络时间并同步本地时间

通过TCP形式来获取NTP时间.主要代码如下: [DllImport("kernel32.dll")] private static extern bool SetLocalTime(ref Systemtime time); [StructLayout(LayoutKind.Sequential)] private struct Systemtime { public short year; public short month; public short dayOfWeek; pu

获取系统时间&amp;&amp;获取程序某一段执行时间

获取系统时间: CTime  _time; CString m_SystemTime("");  _time=CTime::GetCurrentTime();  m_SystemTime=_time.Format("%Y-%m-%d  %H:%M:%S"); 获取程序某一段执行时间: DWORD  betime(0),endtime(0),sumtime(0); int i=0; betime=GetTickCount(); while(i<10) {  Sl