如何格式化BC日期(例如"-700-01-01")? [英] How to format BC dates (like "-700-01-01")?

查看:123
本文介绍了如何格式化BC日期(例如"-700-01-01")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Moment.js格式化ISO日期BC?

How to format ISO dates BC with Moment.js?

moment("-700-01-01").year();     // 700 (WRONG)
moment("-0700-01-01").year();    // 700 (WRONG)
moment("-000700-01-01").year();  // -700 (RIGHT)

出于某种原因,使用6位数的年份表示法是可行的.这是正确"的方式吗?为什么像"-700-01-01"这样的符号不起作用?

For some reason a year notation with 6 digits works. Is that the "right" way? Why doesn't notation like "-700-01-01" work?

推荐答案

这不是Moment.js特有的问题;如果您还尝试使用所使用的字符串初始化Date()对象,也会发生相同的情况.如果首先将其创建为Date()对象,然后使用setYear()手动分配年份,则它确实会接受-700的日期:

This isn't a Moment.js-specific problem; the same happens if you attempt to initialise a Date() object with the string you're using as well. If you create it as a Date() object first and manually assign the year using setYear() it does accept a date of -700:

var date = new Date();

date.setYear(-700);

moment(date).year();

> -700

但是尼尔斯·库伦杰斯(Niels Keurentjes)指出,很久以前的日期计算变得非常复杂,可能根本不可靠.

However as Niels Keurentjes has pointed out, date calculations this far back get quite complicated and may not be at all reliable.

如果要"-700-01-01",则可以分别配置年,月和日:

If you want "-700-01-01" you can configure the year, month and day separately:

date.setYear(-700);
date.setMonth(0);
date.setDate(1);

console.log(date);

> Fri Jan 01 -700 11:53:57 GMT+0000 (GMT Standard Time)

关于公元前700年第一个月的第一天实际上是否是星期五……您必须亲自检查一下.

As to whether the 1st day of the 1st month in 700BC was actually a Friday... you'll have to look that one up yourself.

这篇关于如何格式化BC日期(例如"-700-01-01")?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆