php格式化日期和时间格式化示例分享_php实例
// 格式化日期
static function formatDate($format, $datetime, $week = 0) {
$datetime = $datetime > 3000 ? $datetime : strtotime($datetime);
if ($week) {
$weeknames = [
'日',
'一',
'二',
'三',
'四',
'五',
'六'
];
$format = str_replace('w', $weeknames [date('w', $datetime)], $format);
}
return date($format, $datetime);
}
echo "周" . formatDate("w","2012-11-03 00:46:22" , 1) . " " . formatDate("Y-m-d", "2012-11-03 00:46:22");
echo "周" . formatDate("w","1388678400" , 1) . " " . formatDate("Y-m-d", "1388678400");
周六 2012-11-03
周五 2014-01-03

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





In Python, we have some built-in time functions such as strftime() and datetime.now() which can be used to find the time in AM/PM format. Time in AM/PM format is used in a variety of applications such as user interfaces, reporting and documentation, data visualization, and event scheduling. When the time is between 11:59:00 midnight and 12 noon, we say AM time. Similarly, we can say that the time between 12 o'clock and 11:59:00 midnight is PM. The abbreviations AM/PM are used to indicate the exact time. Syntax uses the following syntax in the example &miinus;strftime('%I:%M:%S%p')strft

AGson isaJSONlibraryforJava,whichiscreatedbyGoogle.ByusingGson,wecangenerateJSONandconvertJSONtojavaobjects.WecancreateaGsoninstancebycreatingaGsonBuilderinstance and calling withthe create()method.TheGson

Format dates and times using the new DateTimeFormatter class in Java 11 Java 11 introduces a new date and time API that contains many new classes and methods to handle dates and times. Among these new classes, the DateTimeFormatter class is one of the key classes used for formatting and parsing dates and times. In this article, we will explain how to use the DateTimeFormatter class to format dates and times and provide some code

In PHP programming, date formatting is a frequently required operation, and is generally accomplished using the date() function. The date() function can format the date according to the external input parameters, and can also operate the timestamp and return the formatted date string. Use the date() function to conveniently format and output the desired date format. The following are some commonly used methods for formatting dates with the date() function: Output date (month-day-year) format echodate('m-d-Y'); //For example

PHP is a commonly used programming language used to develop web applications. In the process of developing web applications, it may involve time conversion in different time zones, such as converting American time to Chinese time. This article will detail the steps on how to use PHP to convert American time to Chinese time and provide code examples. 1. Get the US time First, we need to get the US time. The time zone can be set using PHP's built-in function date_default_timezone_set

How to solve Java time format exception (DateTimeFormatException) Introduction: Java is a widely used programming language, and format exceptions (DateTimeFormatException) are often encountered when processing dates and times. This article will explain how to resolve time formatting exceptions in Java and provide some code examples. 1. What is time formatting exception (DateTimeFormatException) in Java

How to use the TIME_FORMAT function in MySQL to format time into a specific string MySQL is a widely used relational database management system that provides a wealth of functions and operators to process data. In MySQL, there is a very useful function, the TIME_FORMAT function, which can format the time in a specified format and return a string. The basic syntax of the TIME_FORMAT function is as follows: TIME_FORMAT(time,f

The PHP date function is an important feature in the PHP language and can implement various time-related functions. In this article, we will summarize the usage of some commonly used PHP date functions to help readers better understand and use them. 1. Get the current time One of the most commonly used functions in PHP date functions is the date() function, which can get the current date and time. Its basic usage is as follows: date(format, timestamp) where the format parameter specifies the format of date and time, t
