从JS日期对象获取YYYYMMDD格式的字符串?

发布于 2024-09-06 10:51:24 字数 174 浏览 3 评论 0原文

我正在尝试使用 JS 将 date 对象 转换为 YYYYMMDD 格式的字符串。有没有比连接 Date.getYear()Date.getMonth()Date.getDay() 更简单的方法?

I'm trying to use JS to turn a date object into a string in YYYYMMDD format. Is there an easier way than concatenating Date.getYear(), Date.getMonth(), and Date.getDay()?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

风为裳 2024-09-13 10:51:24

修改了我经常使用的代码:

Date.prototype.yyyymmdd = function() {
  var mm = this.getMonth() + 1; // getMonth() is zero-based
  var dd = this.getDate();

  return [this.getFullYear(),
          (mm>9 ? '' : '0') + mm,
          (dd>9 ? '' : '0') + dd
         ].join('');
};

var date = new Date();
date.yyyymmdd();

Altered piece of code I often use:

Date.prototype.yyyymmdd = function() {
  var mm = this.getMonth() + 1; // getMonth() is zero-based
  var dd = this.getDate();

  return [this.getFullYear(),
          (mm>9 ? '' : '0') + mm,
          (dd>9 ? '' : '0') + dd
         ].join('');
};

var date = new Date();
date.yyyymmdd();
糖粟与秋泊 2024-09-13 10:51:24

我不喜欢添加到原型中。另一种选择是:

var rightNow = new Date();
var res = rightNow.toISOString().slice(0,10).replace(/-/g,"");

<!-- Next line is for code snippet output only -->
document.body.innerHTML += res;

I didn't like adding to the prototype. An alternative would be:

var rightNow = new Date();
var res = rightNow.toISOString().slice(0,10).replace(/-/g,"");

<!-- Next line is for code snippet output only -->
document.body.innerHTML += res;

桃扇骨 2024-09-13 10:51:24

您可以使用 toISOString 函数:

var today = new Date();
today.toISOString().substring(0, 10);

它将为您提供“yyyy-mm-dd”格式。

You can use the toISOString function :

var today = new Date();
today.toISOString().substring(0, 10);

It will give you a "yyyy-mm-dd" format.

聚集的泪 2024-09-13 10:51:24

Moment.js 可能是你的朋友

var date = new Date();
var formattedDate = moment(date).format('YYYYMMDD');

Moment.js could be your friend

var date = new Date();
var formattedDate = moment(date).format('YYYYMMDD');
煞人兵器 2024-09-13 10:51:24
new Date('Jun 5 2016').
  toLocaleString('en-us', {year: 'numeric', month: '2-digit', day: '2-digit'}).
  replace(/(\d+)\/(\d+)\/(\d+)/, '$3-$1-$2');

// => '2016-06-05'
new Date('Jun 5 2016').
  toLocaleString('en-us', {year: 'numeric', month: '2-digit', day: '2-digit'}).
  replace(/(\d+)\/(\d+)\/(\d+)/, '$3-$1-$2');

// => '2016-06-05'
裸钻 2024-09-13 10:51:24

如果你不需要纯 JS 解决方案,你可以使用 jQuery UI 来完成这样的工作:

$.datepicker.formatDate('yymmdd', new Date());

我通常不喜欢导入太多的库。但 jQuery UI 非常有用,您可能会在项目的其他地方使用它。

访问 http://api.jqueryui.com/datepicker/ 了解更多示例

If you don't need a pure JS solution, you can use jQuery UI to do the job like this :

$.datepicker.formatDate('yymmdd', new Date());

I usually don't like to import too much libraries. But jQuery UI is so useful, you will probably use it somewhere else in your project.

Visit http://api.jqueryui.com/datepicker/ for more examples

空城之時有危險 2024-09-13 10:51:24

这是一行代码,您可以使用它创建今天日期的 YYYY-MM-DD 字符串。

var d = new Date().toISOString().slice(0,10);

This is a single line of code that you can use to create a YYYY-MM-DD string of today's date.

var d = new Date().toISOString().slice(0,10);
星軌x 2024-09-13 10:51:24

我不喜欢修改本机对象,并且我认为乘法比填充可接受的解决方案的字符串更清晰。

function yyyymmdd(dateIn) {
  var yyyy = dateIn.getFullYear();
  var mm = dateIn.getMonth() + 1; // getMonth() is zero-based
  var dd = dateIn.getDate();
  return String(10000 * yyyy + 100 * mm + dd); // Leading zeros for mm and dd
}

var today = new Date();
console.log(yyyymmdd(today));

小提琴:http://jsfiddle.net/gbdarren/Ew7Y4/

I don't like modifying native objects, and I think multiplication is clearer than the string padding the accepted solution.

function yyyymmdd(dateIn) {
  var yyyy = dateIn.getFullYear();
  var mm = dateIn.getMonth() + 1; // getMonth() is zero-based
  var dd = dateIn.getDate();
  return String(10000 * yyyy + 100 * mm + dd); // Leading zeros for mm and dd
}

var today = new Date();
console.log(yyyymmdd(today));

Fiddle: http://jsfiddle.net/gbdarren/Ew7Y4/

怀里藏娇 2024-09-13 10:51:24

当地时间:

var date = new Date();
date = date.toJSON().slice(0, 10);

UTC 时间:

var date = new Date().toISOString();
date = date.substring(0, 10);

当我写这篇文章时,日期将打印为 2020-06-15。

toISOString() 方法返回符合 ISO 标准的日期,即 YYYY-MM-DDTHH:mm:ss.sssZ

该代码采用 YYYY-MM-DD 格式所需的前 10 个字符。

如果您想要不带“-”的格式,请使用:

var date = new Date();
date = date.toJSON().slice(0, 10).split`-`.join``;

在 .join`` 中,您可以添加空格、点或任何您想要的内容。

Local time:

var date = new Date();
date = date.toJSON().slice(0, 10);

UTC time:

var date = new Date().toISOString();
date = date.substring(0, 10);

date will print 2020-06-15 today as i write this.

toISOString() method returns the date with the ISO standard which is YYYY-MM-DDTHH:mm:ss.sssZ

The code takes the first 10 characters that we need for a YYYY-MM-DD format.

If you want format without '-' use:

var date = new Date();
date = date.toJSON().slice(0, 10).split`-`.join``;

In .join`` you can add space, dots or whatever you'd like.

南风起 2024-09-13 10:51:24

除了 oo 的答案之外,我还建议将逻辑操作与返回值分开,并将它们作为三元组放在变量中。

另外,使用 concat() 来确保变量的安全串联

Date.prototype.yyyymmdd = function() {
  var yyyy = this.getFullYear();
  var mm = this.getMonth() < 9 ? "0" + (this.getMonth() + 1) : (this.getMonth() + 1); // getMonth() is zero-based
  var dd = this.getDate() < 10 ? "0" + this.getDate() : this.getDate();
  return "".concat(yyyy).concat(mm).concat(dd);
};

Date.prototype.yyyymmddhhmm = function() {
  var yyyymmdd = this.yyyymmdd();
  var hh = this.getHours() < 10 ? "0" + this.getHours() : this.getHours();
  var min = this.getMinutes() < 10 ? "0" + this.getMinutes() : this.getMinutes();
  return "".concat(yyyymmdd).concat(hh).concat(min);
};

Date.prototype.yyyymmddhhmmss = function() {
  var yyyymmddhhmm = this.yyyymmddhhmm();
  var ss = this.getSeconds() < 10 ? "0" + this.getSeconds() : this.getSeconds();
  return "".concat(yyyymmddhhmm).concat(ss);
};

var d = new Date();
document.getElementById("a").innerHTML = d.yyyymmdd();
document.getElementById("b").innerHTML = d.yyyymmddhhmm();
document.getElementById("c").innerHTML = d.yyyymmddhhmmss();
<div>
  yyyymmdd: <span id="a"></span>
</div>
<div>
  yyyymmddhhmm: <span id="b"></span>
</div>
<div>
  yyyymmddhhmmss: <span id="c"></span>
</div>

In addition to o-o's answer I'd like to recommend separating logic operations from the return and put them as ternaries in the variables instead.

Also, use concat() to ensure safe concatenation of variables

Date.prototype.yyyymmdd = function() {
  var yyyy = this.getFullYear();
  var mm = this.getMonth() < 9 ? "0" + (this.getMonth() + 1) : (this.getMonth() + 1); // getMonth() is zero-based
  var dd = this.getDate() < 10 ? "0" + this.getDate() : this.getDate();
  return "".concat(yyyy).concat(mm).concat(dd);
};

Date.prototype.yyyymmddhhmm = function() {
  var yyyymmdd = this.yyyymmdd();
  var hh = this.getHours() < 10 ? "0" + this.getHours() : this.getHours();
  var min = this.getMinutes() < 10 ? "0" + this.getMinutes() : this.getMinutes();
  return "".concat(yyyymmdd).concat(hh).concat(min);
};

Date.prototype.yyyymmddhhmmss = function() {
  var yyyymmddhhmm = this.yyyymmddhhmm();
  var ss = this.getSeconds() < 10 ? "0" + this.getSeconds() : this.getSeconds();
  return "".concat(yyyymmddhhmm).concat(ss);
};

var d = new Date();
document.getElementById("a").innerHTML = d.yyyymmdd();
document.getElementById("b").innerHTML = d.yyyymmddhhmm();
document.getElementById("c").innerHTML = d.yyyymmddhhmmss();
<div>
  yyyymmdd: <span id="a"></span>
</div>
<div>
  yyyymmddhhmm: <span id="b"></span>
</div>
<div>
  yyyymmddhhmmss: <span id="c"></span>
</div>

×纯※雪 2024-09-13 10:51:24

纯 JS (ES5) 解决方案,没有任何由 UTC 中的 Date.toISOString() 打印引起的可能的日期跳转问题:

var now = new Date();
var todayUTC = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()));
return todayUTC.toISOString().slice(0, 10).replace(/-/g, '');

这是对 @weberste 对 @Pierre Guilbert 答案的评论的回应。

Plain JS (ES5) solution without any possible date jump issues caused by Date.toISOString() printing in UTC:

var now = new Date();
var todayUTC = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()));
return todayUTC.toISOString().slice(0, 10).replace(/-/g, '');

This in response to @weberste's comment on @Pierre Guilbert's answer.

爱殇璃 2024-09-13 10:51:24
// UTC/GMT 0
document.write('UTC/GMT 0: ' + (new Date()).toISOString().slice(0, 19).replace(/[^0-9]/g, "")); // 20150812013509

// Client local time
document.write('<br/>Local time: ' + (new Date(Date.now()-(new Date()).getTimezoneOffset() * 60000)).toISOString().slice(0, 19).replace(/[^0-9]/g, "")); // 20150812113509

// UTC/GMT 0
document.write('UTC/GMT 0: ' + (new Date()).toISOString().slice(0, 19).replace(/[^0-9]/g, "")); // 20150812013509

// Client local time
document.write('<br/>Local time: ' + (new Date(Date.now()-(new Date()).getTimezoneOffset() * 60000)).toISOString().slice(0, 19).replace(/[^0-9]/g, "")); // 20150812113509

南城旧梦 2024-09-13 10:51:24

另一种方法是使用 toLocaleDateString 具有 big-endian 的语言环境日期格式标准,例如瑞典、立陶宛、匈牙利、韩国……:

date.toLocaleDateString('se')

删除分隔符(-)只需替换非数字即可:

console.log( new Date().toLocaleDateString('se').replace(/\D/g, '') );

这不会出现使用 UTC 日期格式时可能出现的潜在错误:与本地时区的日期相比,UTC 日期可能会少一天。

Another way is to use toLocaleDateString with a locale that has a big-endian date format standard, such as Sweden, Lithuania, Hungary, South Korea, ...:

date.toLocaleDateString('se')

To remove the delimiters (-) is just a matter of replacing the non-digits:

console.log( new Date().toLocaleDateString('se').replace(/\D/g, '') );

This does not have the potential error you can get with UTC date formats: the UTC date may be one day off compared to the date in the local time zone.

素年丶 2024-09-13 10:51:24
var someDate = new Date();
var dateFormated = someDate.toISOString().substr(0,10);

console.log(dateFormated);

var someDate = new Date();
var dateFormated = someDate.toISOString().substr(0,10);

console.log(dateFormated);

对你而言 2024-09-13 10:51:24

dateformat 是一个非常常用的包。

如何使用:

从 NPM 下载并安装dateformat。在您的模块中需要它:

const dateFormat = require('dateformat');

,然后格式化您的内容:

const myYYYYmmddDate = dateformat(new Date(), 'yyyy-mm-dd' );

dateformat is a very used package.

How to use:

Download and install dateformat from NPM. Require it in your module:

const dateFormat = require('dateformat');

and then just format your stuff:

const myYYYYmmddDate = dateformat(new Date(), 'yyyy-mm-dd');

风筝有风,海豚有海 2024-09-13 10:51:24

接受的答案有一点变化:

function getDate_yyyymmdd() {

    const date = new Date();

    const yyyy = date.getFullYear();
    const mm = String(date.getMonth() + 1).padStart(2,'0');
    const dd = String(date.getDate()).padStart(2,'0');

    return `${yyyy}${mm}${dd}`
}

console.log(getDate_yyyymmdd())

A little variation for the accepted answer:

function getDate_yyyymmdd() {

    const date = new Date();

    const yyyy = date.getFullYear();
    const mm = String(date.getMonth() + 1).padStart(2,'0');
    const dd = String(date.getDate()).padStart(2,'0');

    return `${yyyy}${mm}${dd}`
}

console.log(getDate_yyyymmdd())

狠疯拽 2024-09-13 10:51:24

最短

.toJSON().slice(0,10).split`-`.join``;

let d = new Date();

let s = d.toJSON().slice(0,10).split`-`.join``;

console.log(s);

Shortest

.toJSON().slice(0,10).split`-`.join``;

let d = new Date();

let s = d.toJSON().slice(0,10).split`-`.join``;

console.log(s);

述情 2024-09-13 10:51:24

根据 @oo 的答案,这将根据格式字符串返回日期字符串。您可以轻松地为年份和年份添加 2 位数字的年份正则表达式。毫秒之类的,如果你需要的话。

Date.prototype.getFromFormat = function(format) {
    var yyyy = this.getFullYear().toString();
    format = format.replace(/yyyy/g, yyyy)
    var mm = (this.getMonth()+1).toString(); 
    format = format.replace(/mm/g, (mm[1]?mm:"0"+mm[0]));
    var dd  = this.getDate().toString();
    format = format.replace(/dd/g, (dd[1]?dd:"0"+dd[0]));
    var hh = this.getHours().toString();
    format = format.replace(/hh/g, (hh[1]?hh:"0"+hh[0]));
    var ii = this.getMinutes().toString();
    format = format.replace(/ii/g, (ii[1]?ii:"0"+ii[0]));
    var ss  = this.getSeconds().toString();
    format = format.replace(/ss/g, (ss[1]?ss:"0"+ss[0]));
    return format;
};

d = new Date();
var date = d.getFromFormat('yyyy-mm-dd hh:ii:ss');
alert(date);

然而,我不知道它的效率如何,尤其是性能方面,因为它使用了大量的正则表达式。它可能会使用一些我不掌握纯js的工作。

注意:我保留了预定义的类定义,但您可能想根据最佳实践将其放入函数或自定义类中。

Working from @o-o's answer this will give you back the string of the date according to a format string. You can easily add a 2 digit year regex for the year & milliseconds and the such if you need them.

Date.prototype.getFromFormat = function(format) {
    var yyyy = this.getFullYear().toString();
    format = format.replace(/yyyy/g, yyyy)
    var mm = (this.getMonth()+1).toString(); 
    format = format.replace(/mm/g, (mm[1]?mm:"0"+mm[0]));
    var dd  = this.getDate().toString();
    format = format.replace(/dd/g, (dd[1]?dd:"0"+dd[0]));
    var hh = this.getHours().toString();
    format = format.replace(/hh/g, (hh[1]?hh:"0"+hh[0]));
    var ii = this.getMinutes().toString();
    format = format.replace(/ii/g, (ii[1]?ii:"0"+ii[0]));
    var ss  = this.getSeconds().toString();
    format = format.replace(/ss/g, (ss[1]?ss:"0"+ss[0]));
    return format;
};

d = new Date();
var date = d.getFromFormat('yyyy-mm-dd hh:ii:ss');
alert(date);

I don't know how efficient that is however, especially perf wise because it uses a lot of regex. It could probably use some work I do not master pure js.

NB: I've kept the predefined class definition but you might wanna put that in a function or a custom class as per best practices.

甜尕妞 2024-09-13 10:51:24

这家伙在这里 => http://blog.stevenlevithan.com/archives/date-time-format为 Javascript 的 Date 对象编写了一个 format() 函数,因此它可以与熟悉的文字格式一起使用。

如果您需要在应用程序的 Javascript 中使用全功能的日期格式,请使用它。否则,如果您想做的是一次性的,那么连接 getYear()、getMonth()、getDay() 可能是最简单的。

This guy here => http://blog.stevenlevithan.com/archives/date-time-format wrote a format() function for the Javascript's Date object, so it can be used with familiar literal formats.

If you need full featured Date formatting in your app's Javascript, use it. Otherwise if what you want to do is a one off, then concatenating getYear(), getMonth(), getDay() is probably easiest.

征棹 2024-09-13 10:51:24

此线程中最流行的答案的一点简化版本 https://stackoverflow.com/a/3067896/5437379

function toYYYYMMDD(d) {
    var yyyy = d.getFullYear().toString();
    var mm = (d.getMonth() + 101).toString().slice(-2);
    var dd = (d.getDate() + 100).toString().slice(-2);
    return yyyy + mm + dd;
}

Little bit simplified version for the most popular answer in this thread https://stackoverflow.com/a/3067896/5437379 :

function toYYYYMMDD(d) {
    var yyyy = d.getFullYear().toString();
    var mm = (d.getMonth() + 101).toString().slice(-2);
    var dd = (d.getDate() + 100).toString().slice(-2);
    return yyyy + mm + dd;
}
望笑 2024-09-13 10:51:24

您可以简单地使用这一行代码来获取年份中的日期

var date = new Date().getFullYear() + "-" + (parseInt(new Date().getMonth()) + 1) + "-" + new Date().getDate();

You can simply use This one line code to get date in year

var date = new Date().getFullYear() + "-" + (parseInt(new Date().getMonth()) + 1) + "-" + new Date().getDate();
﹂绝世的画 2024-09-13 10:51:24

使用padStart

Date.prototype.yyyymmdd = function() {
    return [
        this.getFullYear(),
        (this.getMonth()+1).toString().padStart(2, '0'), // getMonth() is zero-based
        this.getDate().toString().padStart(2, '0')
    ].join('-');
};

Use padStart:

Date.prototype.yyyymmdd = function() {
    return [
        this.getFullYear(),
        (this.getMonth()+1).toString().padStart(2, '0'), // getMonth() is zero-based
        this.getDate().toString().padStart(2, '0')
    ].join('-');
};
娇俏 2024-09-13 10:51:24
[day,,month,,year]= Intl.DateTimeFormat(undefined, { year: 'numeric', month: '2-digit', day: '2-digit' }).formatToParts(new Date()),year.value+month.value+day.value

或者

new Date().toJSON().slice(0,10).replace(/\/|-/g,'')
[day,,month,,year]= Intl.DateTimeFormat(undefined, { year: 'numeric', month: '2-digit', day: '2-digit' }).formatToParts(new Date()),year.value+month.value+day.value

or

new Date().toJSON().slice(0,10).replace(/\/|-/g,'')
不必你懂 2024-09-13 10:51:24

此代码修复了 Pierre Guilbert 的答案:(

即使在 10000 年后仍然有效)

YYYYMMDD=new Date().toISOString().slice(0,new Date().toISOString().indexOf("T")).replace(/-/g,"")

This code is fix to Pierre Guilbert's answer:

(it works even after 10000 years)

YYYYMMDD=new Date().toISOString().slice(0,new Date().toISOString().indexOf("T")).replace(/-/g,"")
旧人 2024-09-13 10:51:24

回答另一个简单性问题可读性。
此外,不鼓励使用新方法编辑现有的预定义类成员:

function getDateInYYYYMMDD() {
    let currentDate = new Date();

    // year
    let yyyy = '' + currentDate.getFullYear();

    // month
    let mm = ('0' + (currentDate.getMonth() + 1));  // prepend 0 // +1 is because Jan is 0
    mm = mm.substr(mm.length - 2);                  // take last 2 chars

    // day
    let dd = ('0' + currentDate.getDate());         // prepend 0
    dd = dd.substr(dd.length - 2);                  // take last 2 chars

    return yyyy + "" + mm + "" + dd;
}

var currentDateYYYYMMDD = getDateInYYYYMMDD();
console.log('currentDateYYYYMMDD: ' + currentDateYYYYMMDD);

Answering another for Simplicity & readability.
Also, editing existing predefined class members with new methods is not encouraged:

function getDateInYYYYMMDD() {
    let currentDate = new Date();

    // year
    let yyyy = '' + currentDate.getFullYear();

    // month
    let mm = ('0' + (currentDate.getMonth() + 1));  // prepend 0 // +1 is because Jan is 0
    mm = mm.substr(mm.length - 2);                  // take last 2 chars

    // day
    let dd = ('0' + currentDate.getDate());         // prepend 0
    dd = dd.substr(dd.length - 2);                  // take last 2 chars

    return yyyy + "" + mm + "" + dd;
}

var currentDateYYYYMMDD = getDateInYYYYMMDD();
console.log('currentDateYYYYMMDD: ' + currentDateYYYYMMDD);
清欢 2024-09-13 10:51:24

Day.js 怎么样?

只有 2KB,而且您还可以 dayjs().format('YYYY-MM-DD')

https://github.com/iamkun/dayjs

How about Day.js?

It's only 2KB, and you can also dayjs().format('YYYY-MM-DD').

https://github.com/iamkun/dayjs

顾冷 2024-09-13 10:51:24
const date = new Date()

console.log(date.toISOString().split('T')[0]) // 2022-12-27
const date = new Date()

console.log(date.toISOString().split('T')[0]) // 2022-12-27
请持续率性 2024-09-13 10:51:24

如果您不介意包含一个额外的(但很小)库,Sugar.js 提供了许多很好的功能来使用JavaScript 中的 日期
要格式化日期,请使用 format 函数:

new Date().format("{yyyy}{MM}{dd}")

If you don't mind including an additional (but small) library, Sugar.js provides lots of nice functionality for working with dates in JavaScript.
To format a date, use the format function:

new Date().format("{yyyy}{MM}{dd}")
别想她 2024-09-13 10:51:24

当我需要这样做时,我通常使用下面的代码。

var date = new Date($.now());
var dateString = (date.getFullYear() + '-'
    + ('0' + (date.getMonth() + 1)).slice(-2)
    + '-' + ('0' + (date.getDate())).slice(-2));
console.log(dateString); //Will print "2015-09-18" when this comment was written

解释一下,.slice(-2) 为我们提供了字符串的最后两个字符。

因此,无论如何,我们都可以在日期或月份中添加“0”,然后只要求最后两个,因为这些始终是我们想要的两个。

因此,如果 MyDate.getMonth() 返回 9,它将是:

("0" + "9") // Giving us "09"

因此添加 .slice(-2) 会给出最后两个字符,即:

("0" + "9").slice(-2)

"09"

但如果 date.getMonth() 返回 10,它将是:

("0" + "10") // Giving us "010"

所以添加.slice(-2) 给我们最后两个字符,或者:

("0" + "10").slice(-2)

"10"

I usually use the code below when I need to do this.

var date = new Date($.now());
var dateString = (date.getFullYear() + '-'
    + ('0' + (date.getMonth() + 1)).slice(-2)
    + '-' + ('0' + (date.getDate())).slice(-2));
console.log(dateString); //Will print "2015-09-18" when this comment was written

To explain, .slice(-2) gives us the last two characters of the string.

So no matter what, we can add "0" to the day or month, and just ask for the last two since those are always the two we want.

So if the MyDate.getMonth() returns 9, it will be:

("0" + "9") // Giving us "09"

so adding .slice(-2) on that gives us the last two characters which is:

("0" + "9").slice(-2)

"09"

But if date.getMonth() returns 10, it will be:

("0" + "10") // Giving us "010"

so adding .slice(-2) gives us the last two characters, or:

("0" + "10").slice(-2)

"10"
流心雨 2024-09-13 10:51:24

看来mootools提供了 Date().format(): https://mootools.net/more/docs/1.6.0/Types/Date

我不确定是否值得仅针对此特定任务包含在内。

It seems that mootools provides Date().format(): https://mootools.net/more/docs/1.6.0/Types/Date

I'm not sure if it worth including just for this particular task though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文