In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use time class accurate to millisecond time in java1.8". In daily operation, I believe many people have doubts about how to use time class accurate to millisecond time in java1.8. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubt of "how to use time class accurate to millisecond time in java1.8". Next, please follow the editor to study!
It mainly involves three categories:
SimpleDateFormat, the format used to display the time.
Date, get the time accurate to milliseconds.
Calendar to get the time in calendar format.
The sample code is as follows:
Package baseAPI;import java.util.*; / / Import the required toolkit import java.text.*; / / Import the package class mmm where SimpleDateFormat resides {/ / later, you can get the date and time private SimpleDateFormat sdf = null directly through this class. / / declare the SimpleDateFormat object public String getDate () {/ / get a date: format: yyyy-MM-dd HH:mm:ss.SSS this.sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS"); return this.sdf.format (new Date ()) / / format the current date} public String getDateComplete () {/ / get a date: format: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy / / format the current date} public String getTimeStamp () {/ / get a timestamp this.sdf = new SimpleDateFormat ("yyyyMMddHHmmssSSS"); return this.sdf.format (new Date ()); / / format the current date}}; public class useDate {public static void main (String args []) {mmm dt = new mmm () System.out.println (system date: + dt.getDate ()); System.out.println ("Chinese date:" + dt.getDateComplete ()); System.out.println ("timestamp:" + dt.getTimeStamp ()); Calendar calendar = new GregorianCalendar (); StringBuffer strb= new StringBuffer (); strb.append (calendar.get (Calendar.YEAR)) Strb.append ("-" + (calendar.get (Calendar.MONTH) + 1)); strb.append ("-" + calendar.get (Calendar.DAY_OF_MONTH)); strb.append ("" + calendar.get (Calendar.HOUR_OF_DAY)); strb.append (":" + calendar.get (Calendar.MINUTE)); strb.append (":" + calendar.get (Calendar.SECOND)) Strb.append (":" + calendar.get (Calendar.MILLISECOND)); System.out.println (strb);}}; at this point, the study on "how to use time class accurate to milliseconds in java1.8" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.