How to convert between Date, String and Calendar types
How to convert between Date, String, Calendar types, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
Transforming 1.Calendar into String
/ / get the details of the current time, such as year, month, day, week,date, minutes, seconds, etc.
Calendar calendat = Calendar.getInstance ()
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd")
String dateStr = sdf.format (calendar.getTime ())
Transforming 2.String into Calendar
String str= 2010-5-27
SimpleDateFormat sdf= new SimpleDateFormat ("yyyy-MM-dd")
Date date = sdf.parse (str)
Calendar calendar = Calendar.getInstance ()
Calendar.setTime (date)
Transforming 3.Date into String
SimpleDateFormat sdf= new SimpleDateFormat ("yyyy-MM-dd")
String dateStr=sdf.format (new Date ())
Transforming 4.String into Date
String str= 2010-5-27
SimpleDateFormat sdf= new SimpleDateFormat ("yyyy-MM-dd")
Date birthday = sdf.parse (str)
Transforming 5.Date into Calendar
Calendar calendar = Calendar.getInstance ()
Calendar.setTime (new java.util.Date ())
Transforming 6.Calendar into Date
Calendar calendar = Calendar.getInstance ()
Java.util.Date date = calendar.getTime ()
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.