I want to get a formatted Date in Java

前端 未结 5 1606
广开言路
广开言路 2021-01-24 23:48

I want to get a new Date object with a SimpleDateFormat applied to it. I would like to do something like:

SimpleDateFormat myFormat =         


        
5条回答
  •  无人共我
    2021-01-25 00:29

    I think you're misunderstanding something here about what the Date object is. Date simply holds the information about a point in time - it doesn't have a format at all. When it comes to the String representation of a Date, this is where formatting comes into play. Only worry about the formatting when you are:

    1. Parsing a String representation into a Date object.
    2. Converting a Date back into String representation to display it in a certain way.

提交回复
热议问题