如何将日期时间显示为本地时间而不以时区结尾? [英] How to display date time as local time without the timezone at the end?

查看:52
本文介绍了如何将日期时间显示为本地时间而不以时区结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些表面上的混乱,让我澄清一下.如果可能的话,我希望解决方案在freemarker中完成,而不是在Java中完成.

Due to some seeming confusion, let me clarify. If at all possible I want the solution to be done IN freemarker and not in java.

我有一个日期时间字符串,如下所示:2019-03-12T16:02:00+02:00 我必须以如下特定格式显示此内容:EEEE dd. MMMM yyyy HH:mm 但是,如果我这样做,它会将时间显示为14:02而不是16:02. 它将日期时间转换为UTC,然后显示它.如何使它按原样显示小时和分钟,而最后不带"utc"?或任何与此相关的时区. Tuesday 12. March 2019 16:02是所需的输出.

I have a datetime string that looks like this: 2019-03-12T16:02:00+02:00 I have to show this in a specific format like this: EEEE dd. MMMM yyyy HH:mm However, if I do it like this it shows the time as 14:02 instead of 16:02. It converts the datetime to UTC and then displays it. How do I make it display the hours and minutes as is, just without "utc" at the end? Or any timezone for that matter. Tuesday 12. March 2019 16:02 is the desired output.

我不知道收件人的时区.

I do not know the timezone of the recipient.

使用iso_local_nz给了我美国标准显示,这仍然是错误的.

Using iso_local_nz gives me the american standard display which is STILL wrong.

谢谢.

我已经尝试了几乎所有可以从这里想到的内容: https://freemarker.apache.org/docs/ref_builtins_date.html#ref_builtin_date_iso .

I have tried just about all I can think of from here: https://freemarker.apache.org/docs/ref_builtins_date.html#ref_builtin_date_iso.

departureScheduled?datetime.iso?string("EEEE dd. MMMM yyyy HH:mmz")?capitalize

我使用的配置如下:

config = new Configuration(Configuration.VERSION_2_3_28);
config.setTemplateLoader(new S3TemplateLoader());
config.setDefaultEncoding("UTF-8");
config.setLocalizedLookup(false);
config.setLocale(Locale.forLanguageTag("NO"));
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

输入的字符串是我上面提供的字符串.

The string being fed in is the string I provided above.

推荐答案

到目前为止,这不是一个好的解决方案,但它适用于我遇到的情况,即我想显示的时间在原始字符串之前解析.

This is by far not a good solution, but it works for the one case I have where the time I want to show is in the original string before it is parsed.

departureScheduled?keep_before("+")?datetime.iso?string("EEEE dd. MMMM yyyy HH:mm")?capitalize

请注意 keep_before("+") .

Note the keep_before("+").

上面的解决方案通过删除2019-03-12T16:02:00+02:00+之后的所有内容而起作用.然后,日期时间解析器假定时间为UTC.因此,我通过使用内置的字符串操作函数来避免整个问题,该函数返回不会进一步修改的子字符串:2019-03-12T16:02:00(+00:00).括号显示了它的解释方式.

The solution above works by removing whatever is after the + in 2019-03-12T16:02:00+02:00. Then, the datetime parser assumes that the time is in UTC. Thus, I avoid the entire issue by instead using a built in string manipulation function that returns the substring that will not be modified further: 2019-03-12T16:02:00(+00:00). The bracket shows how it is interpreted.

如果有人有更好的答案,我会将其标记为正确,但是几天后,如果没有给出答案,我会将其标记为对可能有相同问题的任何人都是正确的.

If anybody has a better answer I will mark that as correct, but in a few days time, if no answer has been given, I will mark this as correct for anyone who might have the same problem.

这篇关于如何将日期时间显示为本地时间而不以时区结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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