Convert String to Dateless in Java

How to convert String to Time in java without date, I only need time specifically

String Start_time="04:30";

I used

 DateFormat time=new SimpleDateFormat("hh:mm");
 Time bid_start_time=new Time(time.parse("Start_time").getTime());

I need the value “04:30” in Date.I format; I do not need additional date parameters such as DD / MM / YY

+4
source share
1 answer

You cannot have Dateparts of a calendar date. This is a simple fact of what Daterepresents:

The Date class represents a specific point in time accurate to the millisecond .... represents [s] the specified number of milliseconds since the standard base time, known as the "era", namely January 1, 1970, 00:00:00 GMT.

LocalTime java.time Java 8 (Tutorial), LocalTime Joda-Time . .

LocalTime localTime = LocalTime.parse("04:30");

"1970-01-01", , . "1970-01-01 04:30", . - .

+4

Source: https://habr.com/ru/post/1615935/


All Articles