javascript format date and time function_time and date
function DateUtil(){}/***Function: Format time *Example: DateUtil.Format("yyyy/MM/dd","Thu Nov 9 20:30:37 UTC 0800 2006 "); *Return: 2006/11/09*/DateUtil.Format=function(fmtCode,date){ var result,d,arr_d; var patrn_now_1=/^y{4}-M{ 2}-d{2}sh{2}:m{2}:s{2}$/; var patrn_now_11=/^y{4}-M{1,2}-d{1,2}sh{1 ,2}:m{1,2}:s{1,2}$/; var patrn_now_2=/^y{4}/M{2}/d{2}sh{2}:m{2}:s {2}$/; var patrn_now_22=/^y{4}/M{1,2}/d{1,2}sh{1,2}:m{1,2}:s{1,2}$ /; var patrn_now_3=/^y{4} year M{2} month d{2} day sh{2} hour m{2} minute s{2} second$/; var patrn_now_33=/^y{4} year M{1,2} month d{1,2} day sh{1,2} hour m{1,2} minute s{1,2} second $/; var patrn_date_1=/^y{4}-M{ 2}-d{2}$/; var patrn_date_11=/^y{4}-M{1,2}-d{1,2}$/; var patrn_date_2=/^y{4}/M{2} /d{2}$/; var patrn_date_22=/^y{4}/M{1,2}/d{1,2}$/; var patrn_date_3=/^y{4} year M{2} month d {2}day$/; var patrn_date_33=/^y{4} year M{1,2} month d{1,2} day$/; var patrn_time_1=/^h{2}:m{2}:s {2}$/; var patrn_time_11=/^h{1,2}:m{1,2}:s{1,2}$/; var patrn_time_2=/^h{2} hours m{2} minutes s {2} seconds $/; var patrn_time_22=/^h{1,2} hours m{1,2} minutes s{1,2} seconds$/; var patrn_time_22=/^h{1,2} minutes s{1,2} seconds$/; hh:mm:ss";} if(date){ d=new Date(date); if(isNaN(d)){ msgBox("Illegal time parameter nCorrect time example:nThu Nov 9 20:30:37 UTC 0800 2006n or 2006/ 10/17"); result=arr_d.yyyy "-" arr_d .MM "-" arr_d.dd " " arr_d.hh ":" arr_d.mm ":" arr_d.ss; } else if(patrn_now_11.test(fmtCode)) { arr_d=splitDate(d); result=arr_d.yyyy "-" arr_d.MM "-" arr_d.dd " " arr_d.hh ":" arr_d.mm ":" arr_d.ss; } else if(patrn_now_2.test(fmtCode)) { arr_d=splitDate(d,true) ; result=arr_d.yyyy "/" arr_d.MM "/" arr_d.dd " " arr_d.hh ":" arr_d.mm ":" arr_d.ss; splitDate(d); result=arr_d.yyyy "/" arr_d.MM "/" arr_d.dd " " arr_d.hh ":" arr_d.mm ":" arr_d.ss; } else if(patrn_now_3.test(fmtCode) ) arr_d=splitDate(d,true); "; } else if(patrn_now_33.test(fmtCode)) { arr_d=splitDate(d); result=arr_d.yyyy "year" arr_d.MM "month" arr_d.dd "day" " " arr_d.hh "hour" arr_d .mm "minutes" arr_d.ss "seconds"; } else if(patrn_date_1.test(fmtCode)) { arr_d=splitDate(d,true); result=arr_d.yyyy "-" arr_d.MM "-" arr_d.dd ; } else if(patrn_date_11.test(fmtCode)) { arr_d=splitDate(d); result=arr_d.yyyy "-" arr_d.MM "-" arr_d.dd; } else if(patrn_date_2.test(fmtCode)) { arr_d=splitDate(d,true); result=arr_d.yyyy "/" arr_d.MM "/" arr_d.dd; } else if(patrn_date_22.test(fmtCode)) { arr_d=splitDate(d); result=arr_d.yyyy "/" arr_d.MM "/" arr_d.dd; } else if(patrn_date_3.test(fmtCode)) { arr_d=splitDate(d,true); result=arr_d.yyyy "年" arr_d.MM "月" arr_d.dd "日"; } else if(patrn_date_33.test(fmtCode)) { arr_d=splitDate(d); result=arr_d.yyyy "年" arr_d.MM "月" arr_d.dd "日"; } else if(patrn_time_1.test(fmtCode)){ arr_d=splitDate(d,true); result=arr_d.hh ":" arr_d.mm ":" arr_d.ss; } else if(patrn_time_11.test(fmtCode)){ arr_d=splitDate(d); result=arr_d.hh ":" arr_d.mm ":" arr_d.ss; } else if(patrn_time_2.test(fmtCode)){ arr_d=splitDate(d,true); result=arr_d.hh "时" arr_d.mm "分" arr_d.ss "秒"; } else if(patrn_time_22.test(fmtCode)){ arr_d=splitDate(d); result=arr_d.hh "时" arr_d.mm "分" arr_d.ss "秒"; } else{ msgBox("没有匹配的时间格式!"); return; } return result;};function splitDate(d,isZero){ var yyyy,MM,dd,hh,mm,ss; if(isZero){ yyyy=d.getYear(); MM=(d.getMonth() 1)<10?"0" (d.getMonth() 1):d.getMonth() 1; dd=d.getDate()<10?"0" d.getDate():d.getDate(); hh=d.getHours()<10?"0" d.getHours():d.getHours(); mm=d.getMinutes()<10?"0" d.getMinutes():d.getMinutes(); ss=d.getSeconds()<10?"0" d.getSeconds():d.getSeconds(); }else{ yyyy=d.getYear(); MM=d.getMonth() 1; dd=d.getDate(); hh=d.getHours(); mm=d.getMinutes(); ss=d.getSeconds(); } return {"yyyy":yyyy,"MM":MM,"dd":dd,"hh":hh,"mm":mm,"ss":ss}; }function msgBox(msg){ window.alert(msg);}
例子:
[Ctrl A 全选 注:如需引入外部Js需刷新才能执行

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



Go language provides two dynamic function creation technologies: closure and reflection. closures allow access to variables within the closure scope, and reflection can create new functions using the FuncOf function. These technologies are useful in customizing HTTP routers, implementing highly customizable systems, and building pluggable components.

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

Nowadays, we will inevitably encounter some problems such as being unable to turn on the phone or lagging, such as system crash, but during use, mobile phones have become an indispensable part of our lives. We are often at a loss, and sometimes, there are no solutions to these problems. To help you solve cell phone problems, this article will introduce you to some methods of cell phone format recovery and restore your phone to normal operation. Back up data - protect important information, such as photos and contacts, from being lost during the formatting process. Before formatting your phone, the first thing to consider is to back up important data and files on your phone. To ensure data security, or choose to transfer files to a cloud storage service, you can back it up by connecting to a computer. Use the system's built-in recovery function - simple

The key to writing efficient and maintainable Java functions is: keep it simple. Use meaningful naming. Handle special situations. Use appropriate visibility.

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

The advantages of default parameters in C++ functions include simplifying calls, enhancing readability, and avoiding errors. The disadvantages are limited flexibility and naming restrictions. Advantages of variadic parameters include unlimited flexibility and dynamic binding. Disadvantages include greater complexity, implicit type conversions, and difficulty in debugging.

The benefits of functions returning reference types in C++ include: Performance improvements: Passing by reference avoids object copying, thus saving memory and time. Direct modification: The caller can directly modify the returned reference object without reassigning it. Code simplicity: Passing by reference simplifies the code and requires no additional assignment operations.

The difference between custom PHP functions and predefined functions is: Scope: Custom functions are limited to the scope of their definition, while predefined functions are accessible throughout the script. How to define: Custom functions are defined using the function keyword, while predefined functions are defined by the PHP kernel. Parameter passing: Custom functions receive parameters, while predefined functions may not require parameters. Extensibility: Custom functions can be created as needed, while predefined functions are built-in and cannot be modified.
