是否有任何本地化的常量,例如“今天",“明天",“昨天",乔达或Java日期和时间API中的其他内容?

问题描述:

我必须实现使网站客户能够看到最近的交货日期的功能.几个例子:

I have to implement the functionality which enables the website customer to see the nearest possible day of delivery. A couple of examples:

今天6月20日开始发货

Delivery available Today, June 20

将于6月21日明天交货

Delivery available Tomorrow, June 21

6月24日星期二可以送货

Delivery available Tuesday, June 24

问题是此属性已用6种不同的语言本地化,我想知道是否有一种方法不为时间副词(如"Today")创建本地化属性.和明天"?也许有任何预定义的常量或枚举?

The problem is that this property is localized in 6 different languages and I would like to know if there is a way not to create localized properties for time adverbs like "Today" and "Tomorrow"? Maybe there are any predefined constants or enums?

仅供参考,标准Java和Joda-Time都不具有此类功能.

FYI, neither standard Java nor Joda-Time have such features.

但是,我的lib Time4J 支持相对表达式,例如"today",明天",昨天"或超过90种语言的下一个星期日".使用测试时钟的示例:

However, my lib Time4J supports relative expressions like "today", "tomorrow", "yesterday" or "next Sunday" in 90+ languages. Example using a test clock:

  TimeSource<?> clock = () -> PlainTimestamp.of(2015, 8, 1, 10, 24, 5).atUTC();
  String durationInDays =
      PrettyTime.of(Locale.GERMAN).withReferenceClock(clock).printRelative(
          PlainTimestamp.of(2015, 8, 1, 17, 0).atUTC(),
          Timezone.of(EUROPE.BERLIN),
          TimeUnit.DAYS);
  System.out.println(durationInDays); // heute (german word for today)

您还可以通过调用诸如 PrettyTime.of(Locale.getDefault()).printToday() printNext(Weekday)等.如果您使用的是Android,则可以使用姊妹项目Time4A.已记录.如果您错过一门语言,请告诉我.

You can also get the single translations for those expressions by calling methods like PrettyTime.of(Locale.getDefault()).printToday() or printNext(Weekday) etc. If you are on Android you can use the sister Project Time4A. A list of supported languages is also documented. If you miss a language then please let me know.