Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method of string format conversion based on Chinese standard time in java

Shulou Source: shulou.com Published: 2022-06-02 13:56:30 10月05日 Update

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!

Tags: Format character string standard standard time China time method content variable year month day more version knowledge error utility achievement and then again Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information vpn Microsoft macOS