Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datetime-java-c# #25

Open
ichengzi opened this issue Sep 8, 2020 · 0 comments
Open

datetime-java-c# #25

ichengzi opened this issue Sep 8, 2020 · 0 comments

Comments

@ichengzi
Copy link
Owner

ichengzi commented Sep 8, 2020

java

// 自定义格式化:
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
System.out.println(dtf.format(LocalDateTime.now()));
//2020/09/08 21:04:12
LocalDateTime dt2 = LocalDateTime.parse("2019/11/30 05:16:17", dtf);
System.out.println(dt2);
//2019-11-30T05:16:17

LocalDateTime dt2 = LocalDateTime.parse("2019/11/30 5:16:17", dtf);
// 时间格式异常

org.joda.time.format.DateTimeFormatter pattern = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss");
DateTime dateTime = pattern.parseDateTime("2019/11/30 5:16:17");
System.out.println(dateTime.getZone());
//Asia/Shanghai
System.out.println(dateTime);
//2019-11-30T05:16:17.000+08:00
System.out.println(dateTime.toString("yyyy/MM/dd HH:mm:ss.SSS"));
//2019/11/30 05:16:17.000

org.joda.time.format.DateTimeFormatter pattern1 = DateTimeFormat.forPattern("HH:mm:ss");
DateTime dateTime1 = pattern1.parseDateTime("5:16:17");
System.out.println(dateTime1);
//1970-01-01T05:16:17.000+08:00

c#

DateTime.parse("2019/11/30 5:16:17");
//2020/9/8 5:16:17
DateTime.parse("2019/11/30 05:16:17");
//2020/9/8 5:16:17
DateTime.Parse("5:16:17");// c#的默认日期是当天,java joda datetime默认日期是 1970-01-01
//2020/9/8 5:16:17

DateTime.ToString();
//不提供输出格式时,序列化格式是按照当前线程的Culture里配置的格式。 
//通过修改windows的时间格式,改变展示
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant