java .ics 文件中使用的时间格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10551776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Time format used in .ics file?
提问by Vignesh
I am creating an .ics file in Java, and I need to know what date and time format to use.
我正在用 Java 创建一个 .ics 文件,我需要知道要使用的日期和时间格式。
Here is the current format of my ics file:
这是我的 ics 文件的当前格式:
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTSTART:20120901T180000
DTEND:20120901T183000
SUMMARY:my birthday
LOCATION:Bangalore
DESCRIPTION:Every one is welcome..!! time to party
PRIORITY:3
END:VEVENT
END:VCALENDAR
I used ISO_DATETIME_TIME_ZONE_FORMAT
to convert my date to the required format, but it returned 2012-09-01T18:00:00+00:00
我曾经ISO_DATETIME_TIME_ZONE_FORMAT
将我的日期转换为所需的格式,但它返回2012-09-01T18:00:00+00:00
What is the date format used in the DTSTART
and DTEND
values? Specifically, how can I format this properly in Java?
DTSTART
和DTEND
值中使用的日期格式是什么?具体来说,如何在 Java 中正确格式化它?
回答by Roger Lindsj?
With Java you could use
使用 Java,您可以使用
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
See more at iCalendar RFC 5545
在iCalendar RFC 5545 中查看更多信息
回答by smooth reggae
回答by Jeffrey Chen
Building off of Roger's answer, I wrote a quick block of code for anyone who wants a quick online "converter".
基于 Roger 的回答,我为任何想要快速在线“转换器”的人编写了一个快速代码块。
https://repl.it/repls/SomeNovelFields
https://repl.it/repls/SomeNovelFields
The code to get something compiling and running is here:
编译和运行的代码在这里:
import java.text.DateFormat;
import java.util.Date;
import java.text.SimpleDateFormat;
public class HelloWorld{
public static void main(String []args){
System.out.println("Hello World");
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
try {
Date date = dateFormat.parse("20140110T000732");
System.out.println(date);
} catch(Exception e) {
}
}
}