如何分割日期和时间的完整日期格式 - java [英] How to split full date format in date and time - java
问题描述
我有一个这样的格式的Strings,我在我的例子中看到解析。我试着做出今天的决定。
我的问题是,时间差不多了,我只需要比较那个日期。
下一页我想检查时间是否在两个时间戳之间:HH:mm:ss和.after和.before之间,但有问题,日期几乎在...
主要问题是 - 如何在日期和时间中分解解析的格式,以自己的方式处理每个格式...
thx很多
PS:我在android studio ...
String dtStart = 礼拜23 07:24:59
SimpleDateFormat format = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);
try {
if(new Date()。equals(format.parse(dtStart)))System.out.println(true);
else System.out.println(false);
list.add(new LatLng(lat,lng));
} catch(java.text.ParseException e){
// TODO自动生成的catch块
e.printStackTrace();
}
java.time
使用 java.time 内置于Java 8及更高版本的类。
大部分功能已经被移植到Java 6& 7在 ThreeTen-Backport 中,并进一步适应于 ThreeTen-ABP 。
String dateToParse =2016 -05-23 07:24:59
LocalDateTime dateTime = LocalDateTime.parse(dateToParse,DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm:ss));
LocalDate localDate = dateTime.toLocalDate();
LocalTime localTime = dateTime.toLocalTime();
//比较这里你的日期&时间
i have a loot of Strings in that format you see in my example to parse. I try to make a decision which are today.
My problem is, that the time is almost there and i just need to compare that date.
Next i want to check if time is between two timestamps "HH:mm:ss" with .after and .before but there is the problem, that the date is almost there...
The main question is - how to split that parsed format in date and time to handle each in it's own way...
thx a lot
PS: i'm on android studio ...
String dtStart = "2016-05-23 07:24:59";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
if (new Date().equals(format.parse(dtStart)) ) System.out.println("true");
else System.out.println("false");
list.add(new LatLng(lat, lng));
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
java.time
Use the java.time classes built into Java 8 and later.
Much of the functionality has been back-ported to Java 6 & 7 in ThreeTen-Backport, and further adapted to Android in ThreeTen-ABP.
String dateToParse = "2016-05-23 07:24:59";
LocalDateTime dateTime = LocalDateTime.parse(dateToParse, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
LocalDate localDate = dateTime.toLocalDate();
LocalTime localTime = dateTime.toLocalTime();
// Compare here to your date & time
这篇关于如何分割日期和时间的完整日期格式 - java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!