PHP timestamp and date conversion between the example introduction _php instance

Source: Internet
Author: User

Time conversion function in 1.php

Strtotime ("Today")

Date ("Y-m-d h:i", $unixtime)

2.php to get today's 0-point time stamp

To get a 0-point Unix timestamp, you can use $todaytime=strtotime ("Today"),

Then use Date ("Y-m-d h:i", $todaytime) to convert to a date.

3.php timestamp to date, and display different content according to time, such as just, minutes ago, hours ago, today, yesterday, etc.

/* Time conversion function * *

function Transtime ($ustime) {

$ytime = Date ("y-m-d h:i", $ustime);

$rtime = Date ("N-month J-day H:i", $ustime);

$htime = Date ("H:i", $ustime);

$time = Time ()-$ustime;

$todaytime = Strtotime ("Today");

$time 1 = time ()-$todaytime;

if ($time < 60) {

$str = ' just ';

}else if ($time < 60 * 60) {

$min = Floor ($time/60);

$str = $min. ' Minutes ago ';

}else if ($time < $time 1) {

$str = ' Today '. $htime;

}else{

$str = $rtime;

}

return $str;

}

In this function you can add more comparisons to make the displayed date more specific, such as adding seconds before the day before yesterday and more specific dates.

4.php Date with 0 and no supplement 0

echo Date (' y-m-d '); Show 2012-08-08

echo Date (' y-n-j '); Show 2012-8-8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.