PHP时间工具种
PHP时间工具类
<?phpclass DateUtils { function checkDate($date) { //检查日期是否合法日期 $dateArr = explode ( "-", $date ); if (is_numeric ( $dateArr [0] ) && is_numeric ( $dateArr [1] ) && is_numeric ( $dateArr [2] )) { return checkdate ( $dateArr [1], $dateArr [2], $dateArr [0] ); } return false; } function checkTime($time) { //检查时间是否合法时间 $timeArr = explode ( ":", $time ); if (is_numeric ( $timeArr [0] ) && is_numeric ( $timeArr [1] ) && is_numeric ( $timeArr [2] )) { if (($timeArr [0] >= 0 && $timeArr [0] = 0 && $timeArr [1] = 0 && $timeArr [2] $v ) { $v = ereg_replace ( "^0{1,}", '', trim ( $v ) ); if ($v == '') { $dt [$k] = 0; } } $mt = @gmmktime ( $dt [3], $dt [4], $dt [5], $dt [1], $dt [2], $dt [0] ) - 3600 * $cfg_cli_time; if (! empty ( $mt )) { return $mt; } else { return time (); } } function MyDate($format = 'Y-m-d H:i:s', $timest = 0) { //返回格林威治标准时间 //global $cfg_cli_time='+8'; global $cfg_cli_time; $addtime = $cfg_cli_time * 3600; if (empty ( $format )) { $format = 'Y-m-d H:i:s'; } return gmdate ( $format, $timest + $addtime ); } function floorTime($seconds) { //让日期显示为:XX天XX年以前 $times = ''; $days = floor ( ($seconds / 86400) % 30 ); $hours = floor ( ($seconds / 3600) % 24 ); $minutes = floor ( ($seconds / 60) % 60 ); $seconds = floor ( $seconds % 60 ); if ($seconds >= 1) $times .= $seconds . '秒'; if ($minutes >= 1) $times = $minutes . '分钟 ' . $times; if ($hours >= 1) $times = $hours . '小时 ' . $times; if ($days >= 1) $times = $days . '天'; if ($days > 30) return false; $times .= '前'; return str_replace ( " ", '', $times ); } function transDateToChs($date) { if (empty ( $date )) return '今日'; $y = _date ( 'Y', strtotime ( $date ) ); $m = _date ( 'm', strtotime ( $date ) ); $d = _date ( 'd', strtotime ( $date ) ); return $y . '年' . $m . '月' . $d . '日'; } // 08/31/2004 => 2004-08-31 function TransDateUI($datestr, $type = 'Y-m-d') { if ($datestr == Null) return Null; $target = $datestr; $arr_date = preg_split ( "/\//", $target ); $monthstr = $arr_date [0]; $daystr = $arr_date [1]; $yearstr = $arr_date [2]; $result = date ( $type, mktime ( 0, 0, 0, $monthstr, $daystr, $yearstr ) ); return $result; } // 12/20/2004 10:55 AM => 2004-12-20 10:55:00 function TransDateTimeUI($datestr, $type = 'Y-m-d H:i:s') { if ($datestr == Null) return Null; $target = $datestr; $arr_date = preg_split ( "/\/|\s|:/", $target ); $monthstr = $arr_date [0]; $daystr = $arr_date [1]; $yearstr = $arr_date [2]; $hourstr = $arr_date [3]; $minutesstr = $arr_date [4]; $result = date ( $type, mktime ( $hourstr, $minutesstr, 0, $monthstr, $daystr, $yearstr ) ); return $result; } // 2004-08-31 => 08/31/2004 function TransDateDB($datestr, $type = 'm/d/Y') { if ($datestr == Null) return Null; if ($datestr == '0000-00-00') return Null; $target = $datestr; $arr_date = preg_split ( "/-/", $target ); $monthstr = $arr_date [1]; $daystr = $arr_date [2]; $yearstr = $arr_date [0]; $result = date ( $type, mktime ( 0, 0, 0, $monthstr, $daystr, $yearstr ) ); return $result; } // 2004-08-31 10:55:00 => 12/20/2004 10:55 AM function TransDateTimeDB($datestr, $type = 'm/d/Y h:i A') { if ($datestr == Null) return Null; $target = $datestr; $arr_date = preg_split ( "/-|\s|:/", $target ); $monthstr = $arr_date [1]; $daystr = $arr_date [2]; $yearstr = $arr_date [0]; $hourstr = $arr_date [3]; $minutesstr = $arr_date [4]; $secondstr = $arr_date [5]; $result = date ( $type, mktime ( $hourstr, $minutesstr, $secondstr, $monthstr, $daystr, $yearstr ) ); return $result; }}?>

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

AI Hentai Generator
Generate AI Hentai for free.

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

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

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,

Function means function. It is a reusable code block with specific functions. It is one of the basic components of a program. It can accept input parameters, perform specific operations, and return results. Its purpose is to encapsulate a reusable block of code. code to improve code reusability and maintainability.

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

Source code: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#Output The output of the above code can simply conclude: return is executed before finally. Let's take a look at what happens at the bytecode level. The following intercepts part of the bytecode of the case1 method, and compares the source code to annotate the meaning of each instruction in

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

There are many excellent calendar libraries and date libraries in Python for us to use. These libraries can help us handle date and calendar related operations. Next, I will introduce you to several common choices and provide corresponding code examples. Datetime library: Datetime is Python's built-in date and time processing module. It provides many date and time related classes and methods, which can be used to process dates, times, time differences and other operations. Sample code: importdatetime#Get the current date

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
