Get the App
SLTechnology News&Howtos  ›  Development  › 

The method of converting date in int format in php

Shulou Source: shulou.com Published: 2022-06-03 17:32:52 10月04日 Update

This article introduces the relevant knowledge of "the method of converting dates in int format in php". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Add a time timestamp through "$lasTtime=time ();".

2. Use the "date (" Y-m-d ", $lastTime); method to convert it to a date format.

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 method of converting dates in int format in php". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Time format time method date content hours more knowledge problems output utility learning and then no functions variables dilemmas actually Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker OPPO Reno Xiaomi Shulou Tech Info