Get the App
SLTechnology News&Howtos  ›  Development  › 

How to change date by int in php

Shulou Source: shulou.com Published: 2022-06-03 20:17:42 11月09日 Update

Editor to share with you how to change the date of int in php, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Php int to date method: 1, through "$lasTtime=time ();" add a time timest 2, use "date (" Y-m-d ", $lastTime);" method can be converted to date format.

Operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer

How does php int change the date?

Php converts int types to time types

I encountered the problem of timestamp conversion in this project.

The timestamp of the database design is in int format, all of which require some conversion.

$lasTtime=time (); / / this adds a time timestamp

This timestamp outputs the current time and converts it to int: 1558321414 / / this is the timestamp when I wrote this.

You can use it when you extract it.

$time=date ("Y-m-d", $lastTime); / / date is a function that converts to the format you specify

The timestamp will become: 2019-05-20 11:03:34 / / this is the timestamp when I wrote this.

If you still want to convert 2019-05-20 11:03:34 to int format

$lastTime=strtotime ($time); / / $time is the variable you want to convert

It will eventually become: 1558321414 / / this is the timestamp when I wrote this.

If there is a time difference, you can use date_default_timezone_set ("PRC"); solve the 8-hour jet lag problem

Y-m-d H:i:s'// this is the defined time format / / what is needed / / s is s, minute is I, hour is H, day is d, month is m, and year is Yecho date ('iPrecious timekeeper); / / if you want to calculate with the current time, you don't have to convert it to time type $time_str = 1313994356 access centering time = time ()-$time_str What c_time gets is seconds / minute divided by 60c_time/60 and 5 to compare the above is all the content of the article "how to change dates in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Time date format time article type content hour method problem not much no function variable most that is data database jet lag time difference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple Redmi vpn MariaDB