V
V
vika_san2021-02-01 16:40:36
Java
vika_san, 2021-02-01 16:40:36

How to convert String to Date WITHOUT format change?

Hi all. There is a string 05/01/2020, you need to convert it to Date. I use SimpleDateFormat with the mask dd.MM.yyyy, at the output I get words, time zone, time instead of the original date. How to make a normal date, which was?

DateS = '01.05.2020'
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
Date dateD = format.parse(DateS)


No one knows ?)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Orkhan, 2021-02-01
Hasanly @azerphoenix

If you want structure to match your string then use LocalDate instead of Date
detailed info - https://metanit.com/java/tutorial/12.3.php

D
Dmitry Roo, 2021-02-01
@xez

public static void main(String[] args) throws ParseException {
        var dates = "01.05.2020";
        var format = new SimpleDateFormat("dd.MM.yyyy");
        var dateD = format.parse(dates);
        System.out.println(dateD);
    }

Fri May 01 00:00:00 MSK 2020

Is this the question?

Q
qwesan, 2021-02-03
@qwesan

Because you are parsing the date, and to give the output form to the date, you need to use the format method of SimpleDateFormat

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question