Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert between Date, String and Calendar types

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report