return date type with format in java [duplicate]

青春壹個敷衍的年華 提交于 2019-11-26 22:15:15

问题


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 ?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!