Home Backend Development PHP Tutorial PHP conversion of Unix timestamps

PHP conversion of Unix timestamps

Aug 08, 2016 am 09:31 AM
date quot time unix

Commonly used
1. Convert Unix timestamp into a format similar to "2012-05-12 11:09:15":
date('Y-m-d H:i:s',$time); //$ The value of time is the Unix timestamp, which may be what you took out from the database or...
2. Convert the time in the "2012-05-12" format into a timestamp:
strtotime("2012- 05-12"); //The return value is int type
3. Print the timestamp of the current time:
echo(time());
Advanced
In fact, the date function provided by PHP The function is very easy to use. For example, if you want to convert a Unix timestamp into the date format you want, such as "May 25, 2012":
date('Y year m month d day', $time) ;
You can see that the date function is only interested in "Y", "m", and "d". As for the special characters you inserted in the middle, she doesn't pay much attention.
■Year--"Y" represents the four-digit year. 2012
■Year--"y" represents a two-digit year. 12
■month--"F" means spelling out the English month. January will be displayed as "january"
■month--"M" represents the first 3 characters of the English month. The month of January will be displayed as "jan", the abbreviation of January
■month - "m" represents the numeric month. January is displayed as "01" and December is "12"
■Day--"j" represents a numeric date. If the date is a single digit, "0" will not be added to the high digit, for example: "9", "12"
■Day - "d" represents a numeric date. If the date is a single digit, the high digit will be filled with "0", for example: "09", "12"
■hour - "g" The time in twelve-hour format, if it is a single digit, the high digit will not be filled." 0", for example: "3", "12"
■Hour - "G" is the time in the twenty-four-hour format. If it is a single-digit high digit, "0" will not be added, for example: "3", " 18"
■hour-"h"Twelve-hour time, if it is a single-digit high digit, "0" will be added, for example: "03", "12"
■hour-"H" If the time in the 24-hour format is a single digit, "0" will be added to the high digit, for example: "03", "18"
■ minutes - "i" minutes, for example: "09", "60"
■Seconds--"s" seconds, such as: "06", "60"
Finally, please note that if the time format is output in the twelve-hour format, you need to indicate AM and PM
For example: echo date('g:i:s a');
The output result is: 5:56:57 am
echo date('h:i:s A');
The output result is: 05: 56:57 AM
"a" morning = am, afternoon = pm; "A" morning = AM, afternoon = PM
Popular science
The timestamp is from January 1, 1970 (00:00: 00 GMT). It is also called Unix Timestamp.
Unix timestamp (Unix timestamp), also known as Unix time (Unix time), POSIX time (POSIX time), is a time representation method, defined as starting from 00:00 Greenwich Mean Time on January 1, 1970 The total number of seconds since minute 00 seconds. Unix timestamps are not only used in Unix systems and Unix-like systems, but are also widely used in many other operating systems.

The above introduces PHP's conversion of Unix timestamps, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

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)

What operating system is unix? What operating system is unix? Jan 05, 2021 am 10:26 AM

Unix is ​​a multi-user, multi-process computer operating system that supports multiple processor architectures. According to the classification of operating systems, it is a time-sharing operating system. In addition to being a network operating system, Unix can also be used as a stand-alone operating system. The UNIX system provides a good user interface, which is easy to use, fully functional, clear and flexible, and easy to expand and modify.

What does GNU mean? What does GNU mean? Jan 02, 2019 am 11:53 AM

GNU is a Unix-like operating system developed and designed based on Unix and is compatible with Unix. GNU consists of a set of software applications and developer tools and a program that allocates resources and communicates with hardware or the kernel. GNU can be used with other kernels, and is usually used with the Linux kernel. GNU programs can be ported to many other operating systems, including different platforms such as Mac OS X and Microsoft Windows.

How to create and name a file/folder based on current timestamp How to create and name a file/folder based on current timestamp Apr 27, 2023 pm 11:07 PM

If you're looking for a way to automatically create and name files and folders based on system timestamps, you've come to the right place. There is a super simple way to accomplish this task. The created folders or files can then be used for various purposes such as storing file backups, sorting files based on date, etc. In this article, we will explain in some very simple steps how to automatically create files and folders in Windows 11/10 and name them according to the system’s timestamp. The method used is a batch script, which is very simple. Hope you enjoyed reading this article. Section 1: How to automatically create and name a folder based on the current timestamp of the system Step 1: First, navigate to the parent folder where you want to create the folder,

PHP Warning: date() expects parameter 2 to be long, string given solution PHP Warning: date() expects parameter 2 to be long, string given solution Jun 22, 2023 pm 08:03 PM

When developing using PHP programs, you often encounter some warning or error messages. Among them, one error message that may appear is: PHPWarning:date()expectsparameter2tobelong,stringgiven. The error message means: the second parameter of the function date() is expected to be a long integer (long), but what is actually passed to it is a string (string). So, we

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.

KDE Plasma 6.1 brings many enhancements to the popular Linux desktop KDE Plasma 6.1 brings many enhancements to the popular Linux desktop Jun 23, 2024 am 07:54 AM

After several pre-releases, the KDE Plasma development team unveiled version 6.0 of its desktop environment for Linux and BSD systems on 28 February, using the Qt6 framework for the first time. KDE Plasma 6.1 now comes with a number of new features t

How to get the millisecond representation of a date using the getTime() method of the Date class How to get the millisecond representation of a date using the getTime() method of the Date class Jul 24, 2023 am 11:42 AM

How to get millisecond representation of date using getTime() method of Date class In Java, Date class is a class used to represent date and time. It provides many useful methods to manipulate and obtain information about date objects. Among them, the getTime() method is an important method in the Date class, which can return the millisecond representation of the date object. Next, we will detail how to use this method to obtain the millisecond representation of a date, and provide corresponding code examples. Using the Date class

Introduction to methods and usage of using Date and SimpleDateFormat classes to process time in Java Introduction to methods and usage of using Date and SimpleDateFormat classes to process time in Java Apr 21, 2023 pm 03:01 PM

1. Introduction The Date class in the java.util package represents a specific time, accurate to milliseconds. If we want to use our Date class, then we must introduce our Date class. Writing the year directly into the Date class will not produce the correct result. Because Date in Java is calculated from 1900, so as long as you fill in the first parameter with the number of years since 1900, you will get the year you want. The month needs to be subtracted by 1, and the day can be inserted directly. This method is rarely used, and the second method is commonly used. This method is to convert a string that conforms to a specific format, such as yyyy-MM-dd, into Date type data. First, define an object of Date type Date

See all articles