This question already has an answer here:
- Change the format of Date Java [closed] 2 answers
I'm trying implement get method for variable has type "Date". But when return, I want to return it with format "yyyy/MM/dd" and MUST be Date type.
Example: original date: 2018/01/01T15:00.00.000+0000
I want return: 2018-01-01 and MUST be date, not string
Can you help me in this case ?
A Date
is basically stored as a number of milliseconds since the epoch (1/1/1970). It can be formatted into a String
in various ways (e.g. with SimpleDateFormat
), but it is never stored as a String. So, what you're asking for is impossible and makes no sense.
来源:https://stackoverflow.com/questions/50485203/return-date-type-with-format-in-java