Home Web Front-end JS Tutorial javascript date conversion timestamp to date format_time and date

javascript date conversion timestamp to date format_time and date

May 16, 2016 pm 05:59 PM
date conversion

Copy code The code is as follows:

Date.prototype.format = function(format)
{
var o =
{
"M " : this.getMonth() 1, //month
"d " : this.getDate(), //day
"h " : this .getHours(), //hour
"m " : this.getMinutes(), //minute
"s " : this.getSeconds(), //second
"q " : Math.floor ((this.getMonth() 3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}

if(/(y )/.test (format))
{
format = format.replace(RegExp.$1, (this.getFullYear() "").substr(4 - RegExp.$1.length));
}

for(var k in o)
{
if(new RegExp("(" k ")").test(format))
{
format = format.replace(RegExp .$1, RegExp.$1.length==1 ? o[k] : ("00" o[k]).substr(("" o[k]).length));
}
}
return format;
}
var testDate = new Date( 1320336000000 );//This must be an integer, milliseconds
var testStr = testDate.format("yyyy year MM month dd day hh hour mm Minutes ss seconds");
var testStr2 = testDate.format("yyyyMMdd hh:mm:ss");
alert(testStr " " testStr2);
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

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)

Convert timestamp to date in php Convert timestamp to date in php Apr 09, 2024 pm 02:36 PM

To convert a PHP timestamp to a date, you can use the date() function, the syntax is: date(format, timestamp). Common date format specifiers include: Y (year), m (month), d (day), H (hour), i (minute), and s (second). The code example to convert timestamp 1658096324 to date is: $timestamp=1658096324;$date=date('Y-m-dH:i:s',$timestamp); Output: 2022-07-1914:58:44.

How to fix: Java Date Error: Date conversion error How to fix: Java Date Error: Date conversion error Aug 19, 2023 am 08:08 AM

How to Fix: Java Date Error: Date Conversion Error In Java development, handling dates is a common need. However, sometimes we may encounter a date conversion error problem, that is, the string cannot be converted to a date object or an exception occurs while converting the date object to a string. This article will introduce several common date conversion errors and give corresponding solutions. 1. Date format does not match Date format refers to the representation of a date string, including year, month, day, hour, minute and second, etc. When doing date conversions, you must ensure that the date

Convert php timestamp to human readable date Convert php timestamp to human readable date Apr 09, 2024 am 11:12 AM

In PHP, you can use the date() function to convert a PHP timestamp to a human-readable date: use the date(string$format,int$timestamp=time()) function. Provide the $format parameter to specify the format of the output date. Optionally provide the $timestamp parameter to specify the UNIX timestamp to be converted, defaulting to the current time.

How to convert date to string using universal time convention? How to convert date to string using universal time convention? Aug 19, 2023 pm 07:29 PM

To convert a date to a string using universal time conventions, use the toUTCString() method. It returns a date converted to a string, using universal time conventions. Example You can try running the following code to see how to convert a date to a string using UTC: <html> <head> <title>JavaScripttoUTCStringMethod</title&

How to use the DATE_FORMAT function in MySQL to convert dates to different formats How to use the DATE_FORMAT function in MySQL to convert dates to different formats Jul 12, 2023 am 10:22 AM

How to use the DATE_FORMAT function in MySQL to convert dates into different formats Date is a common data type in databases. In practical applications, we often need to format dates to meet different needs. MySQL provides the DATE_FORMAT function to convert dates into different formats. The syntax of the DATE_FORMAT function is as follows: DATE_FORMAT(date,format) where date is the date to be converted,

How to use the DATE_FORMAT function in MySQL to convert a date into a string in a specified format How to use the DATE_FORMAT function in MySQL to convert a date into a string in a specified format Jul 25, 2023 pm 11:09 PM

How to use the DATE_FORMAT function in MySQL to convert a date into a string in a specified format. In MySQL, we often need to convert date data into a specific format to meet specific needs. In order to achieve this purpose, MySQL provides the DATE_FORMAT function, through which date data can be converted into a string in a specified format. This article will introduce how to use the DATE_FORMAT function to implement this function and give relevant code examples. First, let's see

How to convert date to days in php How to convert date to days in php Jul 11, 2023 pm 04:28 PM

How to convert date to number of days in php: 1. strtotime() function, use this function to convert the date to UNIX timestamp, use the "floor()" function to divide by the number of seconds per day to get the number of days of the date; 2. DateTime class , create a DateTime object, use the "diff()" method to compare the given date with the current date, and then use the "format()" method to get the number of days between dates; 3. Write a custom function to convert the date to the number of days, etc. wait.

Solving common problems in converting PHP numerical values ​​to date format Solving common problems in converting PHP numerical values ​​to date format Mar 23, 2024 am 09:45 AM

As a popular programming language, PHP is widely used in various web development fields. In actual work, we sometimes encounter problems that require converting numerical values ​​into date format. This article will introduce some common problems in converting numerical values ​​to date format in PHP, and provide specific code example solutions. Question 1: Convert timestamp to date format In PHP, timestamp is a common way to represent time, usually an integer representing the number of seconds that have passed since January 1, 1970. If we need to convert a timestamp to

See all articles