Home Backend Development PHP Tutorial php中获取时间的几套步骤(收集)

php中获取时间的几套步骤(收集)

Jun 13, 2016 am 10:56 AM
current floor return time

php中获取时间的几套方法(收集)
1、jddayofweek(cal_to_jd(CAL_GREGORIAN, date('m'), date('d'), date('Y')));此函数返回日期在周几
2、array('Mon'=>'星期一',......);然后直接下标查询
3、根据日期获取周几的自定义函数

<?php function getWeekName($data,$format = '星期')	{	    $week   =  date( "D ",$data);            switch($week)	    {	        case "Mon ":	            $current   =   $format."一";	            break;	        case "Tue ":	            $current   =   $format."二";	            break;	        case "Wed ":	            $current   =   $format."三";	            break;	        case "Thu ":	            $current   =   $format."四";	            break;	        case "Fri ":	            $current   =   $format."五";	            break;	        case "Sat ":	            $current   =   $format."六";	            break;	        case "Sun ":	            $current   =   $format."日";	            break;	    }	    return $current;	}	 	 	echo '今天是:'.getWeekName(time(),'星期');	echo '<br>';	echo '今天是:'.getWeekName(time(),'礼拜');	echo '<br>';	echo '2010-12-12是:'.getWeekName(strtotime('2010-12-12'),'礼拜');	?>
Copy after login

4、获取类似文章发表的几小时前等效果的自定义函数
<?phpfunction time2Units ($time){$year = floor($time / 60 / 60 / 24 / 365);$time -= $year * 60 * 60 * 24 * 365;$month = floor($time / 60 / 60 / 24 / 30);$time -= $month * 60 * 60 * 24 * 30;$week = floor($time / 60 / 60 / 24 / 7);$time -= $week * 60 * 60 * 24 * 7;$day = floor($time / 60 / 60 / 24);$time -= $day * 60 * 60 * 24;$hour = floor($time / 60 / 60);$time -= $hour * 60 * 60;$minute = floor($time / 60);$time -= $minute * 60;$second = $time;$elapse = '';$unitArr = array('年' =>'year', '个月'=>'month', '周'=>'week', '天'=>'day','小时'=>'hour', '分钟'=>'minute', '秒'=>'second');foreach ( $unitArr as $cn => $u ){if ( $$u > 0 ){$elapse = $$u . $cn;break;}}return $elapse;}$past = 2052345678; // 发布日期$now = time(); // 当前日期$diff = $now - $past;//相差值echo '发表于' . time2Units($diff) . '前';?>
Copy after login

另一种,个人认为比较好的:
function time_tran($the_time){$now_time = date("Y-m-d H:i:s",time()+8*60*60);$now_time = strtotime($now_time);$show_time = strtotime($the_time);$dur = $now_time - $show_time;if($dur <br>5、根据两时间差具体算相差时间<br><pre name="code" class="java">function getTime( $val ){if($val>0){$nTime['nDay'] = (int)($val/(3600*24));$nTime['nHour'] = (int)($val%(3600*24)/3600);$nTime['nMin'] = (int)($val%(3600*24)%3600/60);$nTime['nSec'] = (int)($val%(3600*24)%3600%60);}return $nTime ;}function getStrTime( $val ){$aTime = getTime($val);$dtoc = array('nDay'=>'天','nHour'=>'小时','nMin'=>'分','nSec'=>'秒');if( $aTime ){foreach( $aTime as $k=>$v){if($v){$cTime .= $v.$dtoc[$k];}}}else{$cTime = '已结止';}return $cTime;}
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of the usage of return in C language Detailed explanation of the usage of return in C language Oct 07, 2023 am 10:58 AM

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

Monotonic clock processing of time package Monotonic clock processing of time package Aug 04, 2023 pm 05:45 PM

Today we are mainly going to take a look at the time application method of golang time package. The general rule between the two is that "wall time" is used to tell time, and "monotonic clock" is used to measure time; there are other clock processing methods.

What is the execution order of return and finally statements in Java? What is the execution order of return and finally statements in Java? Apr 25, 2023 pm 07:55 PM

Source code: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#Output The output of the above code can simply conclude: return is executed before finally. Let's take a look at what happens at the bytecode level. The following intercepts part of the bytecode of the case1 method, and compares the source code to annotate the meaning of each instruction in

How does Vue3 use setup syntax sugar to refuse to write return How does Vue3 use setup syntax sugar to refuse to write return May 12, 2023 pm 06:34 PM

Vue3.2 setup syntax sugar is a compile-time syntax sugar that uses the combined API in a single file component (SFC) to solve the cumbersome setup in Vue3.0. The declared variables, functions, and content introduced by import are exposed through return, so that they can be used in Vue3.0. Problems in use 1. There is no need to return declared variables, functions and content introduced by import during use. You can use syntactic sugar //import the content introduced import{getToday}from'./utils'//variable constmsg='Hello !'//function func

Use the return keyword in JavaScript Use the return keyword in JavaScript Feb 18, 2024 pm 12:45 PM

Usage of return in JavaScript requires specific code examples In JavaScript, the return statement is used to specify the value returned from a function. Not only can it be used to end the execution of a function, it can also return a value to the place where the function was called. The return statement has the following common uses: Return a value The return statement can be used to return a value to the place where the function is called. Here is a simple example: functionadd(a,b){

Detailed explanation of JavaScript function return values ​​and return statements Detailed explanation of JavaScript function return values ​​and return statements Aug 04, 2022 am 09:46 AM

JavaScript functions provide two interfaces to interact with the outside world. The parameters serve as the entrance to receive external information; the return value serves as the outlet to feed back the operation results to the outside world. The following article will take you to understand the JavaScript function return value and briefly analyze the usage of the return statement. I hope it will be helpful to you!

How to use Java8 Time API How to use Java8 Time API Apr 28, 2023 pm 12:25 PM

1. Overview As part of this article, let us start with some problems with the existing Date and CalendarAPI and explore how the new Java8Date and TimeAPI solve these problems. We will also take a look at the core classes in the Java8 time class library, such as LocalDate, LocalTime, LocalDateTime, ZonedDateTime, Period, Duration and their APIs. 2. The problem of thread safety of the old time API (before Java 8)-Date and Calendar classes are not thread-safe, making it difficult for developers to debug concurrency problems of these APIs and need to write additional code to deal with them.

What is the difference and usage between time and datetime in python What is the difference and usage between time and datetime in python May 02, 2023 am 11:01 AM

1. Two ways to represent time in Python: timestamp: offset in seconds relative to 1970.1.100:00:00, unique time tuple struct_time: a total of 9 elements>tm_year: year 1-12> tm_mon: month 1-12>tm_mday: day 1-31>tm_hour: hour 0-23>tm_min: minute 0-59>tm_sec: second 0-59>tm_wday: week 0-6 (0 means Sunday)>tm_day: Day of the year 1-366>tm_isdst: whether it is daylight saving, the default is -1.ti

See all articles