Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set time format for javascript

Shulou Source: shulou.com Published: 2022-06-03 13:24:15 11月14日 Update

This article introduces the relevant knowledge of "how to set the time format of javascript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Use "new Date (). Format ('yyyy-MM-dd');" to format the time.

2. Output the date in string format through the built-in method of js.

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;} "how to format javascript" is here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Format time content more knowledge output practicality achievement next dilemma character string reality situation article method method date case editing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Huawei Shulou Information Shulou Technology