Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change date by int in php

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report