java 拆分日期和时间,如何分割日期和时间的完整日期格式 - java

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值