本文介绍了年份和年份有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DateTimeFormatter 类文档为年份定义单独的符号 u y 年代:

The DateTimeFormatter class documentation defines separate symbols u for year and y year-of-era: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#patterns

年份之间有什么区别和年代?

What is the difference between year and year-of-era?

推荐答案

答案在于


  • 时代 - 有两个时代,'当前时代'(CE)和'当前时代'(BCE)。

  • 年代 - 年份-era与当前CE时代的预感年相同。对于ISO时代之前的BCE时代,随着时间的推移,年份从1上升。

  • 预感年 - 预感年份与当前年份的年份相同时代。对于上一个时代,年份为零,然后是负值。

u 会给你一个过敏的一年。
y 将为您提供当时的年份。

u will give you the proleptic year.y will give you the year of the era.

差异主要是多年的BC时代。预感0年实际上是公元前1年,其后是公元1年的公元1年。时间可以是负面的,时代的年份不能。

The difference is mainly important for years of the BC era. The proleptic year 0 is actually 1 BC, it is followed by proleptic year 1 which is 1 AD. The proleptic year can be negative, the year of era can not.

这是一个片段,可以帮助想象它是如何工作的:

Here is a snippet that will help visualize how it works :

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("'proleptic' : u '= era:' y G");

for (int i = 5; i > -6 ; i--) {
    LocalDate localDate = LocalDate.of(i, 3, 14);
    System.out.println(formatter.format(localDate));
}

输出:

proleptic : 5 = era: 5 AD
proleptic : 4 = era: 4 AD
proleptic : 3 = era: 3 AD
proleptic : 2 = era: 2 AD
proleptic : 1 = era: 1 AD
proleptic : 0 = era: 1 BC
proleptic : -1 = era: 2 BC
proleptic : -2 = era: 3 BC
proleptic : -3 = era: 4 BC
proleptic : -4 = era: 5 BC
proleptic : -5 = era: 6 BC

这篇关于年份和年份有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 17:47