In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the string format conversion method of java based on Chinese standard time". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The LocalDateTime version is recommended! (an unrejectable version [doge])
Private static void parseByLocalDateTime (String dateStr) {/ / conversion time format = > "Wed Nov 21 2018 00:00:00 GMT+0800 (China Standard time)" dateStr = dateStr.replace ("GMT", "). ReplaceAll ("\ (. *\) ",") .trim (); DateTimeFormatter df = DateTimeFormatter.ofPattern ("EEE MMM dd yyyy HH:mm:ss Z", Locale.US) / / LocalDateTime ldt = LocalDateTime.parse (dateStr, df); / / = > 2018-11-21 14:12:09 System.out.println (ldt.toString (). ReplaceAll ("T", "\")); / / only LocalDate ldt1 = LocalDate.parse (dateStr, df) / / 2018-11-21 System.out.println (ldt1.toString (). ReplaceAll ("T", "\");} private static String parseTime (String dateStr) {/ / conversion time format = > "Wed Nov 21 2018 00:00:00 GMT+0800 (China Standard time)" String parseDate / / define a returned variable / / string to Date / / define a variable SimpleDateFormat sdf = new SimpleDateFormat ("EEE MMM dd yyyy HH:mm:ss' GMT+0800 (China Standard time)'", Locale.US) for formatting strings; Date date = new Date () / / create the Date object try {date = sdf.parse (dateStr); / / parse the target string in the specified format} catch (ParseException e) {log.info ("time format conversion error" + date.toString ()) / / print the error log, or use "System.out.println ()"} / / Date to convert the string sdf = new SimpleDateFormat ("yyyy-MM-dd"); / / re-specify the converted format parseDate = sdf.format (date); / / convert to the specified date format / / parseDate: 2018-11-21 return parseDate / / return the processed result} "what is the string format conversion method of java based on Chinese standard time"? thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.