Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to convert local variables by java SimpleDateFormat

Shulou Source: shulou.com Published: 2022-05-31 10:48:25 10月21日 Update

This article mainly introduces the relevant knowledge of java SimpleDateFormat how to convert local variables, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value, I believe you will have something to gain after reading this java SimpleDateFormat article on how to convert local variables, let's take a look.

Description

1. When SimpleDateFormat is defined as a local variable, each thread monopolizes the SimpleDateFormat target.

2. It is equivalent to changing a multi-thread program into a single-line program, so there is no problem of thread unsafety.

Example

Import java.text.SimpleDateFormat;import java.util.Date;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors; public class SimpleDateFormatExample {public static void main (String [] args) {/ / create thread pool ExecutorService threadPool = Executors.newFixedThreadPool (10); / / execute 10 time formatting for (int I = 0; I < 10; iForm +) {int finalI = I / / Thread pool executes task threadPool.execute (new Runnable () {@ Override public void run () {/ / create SimpleDateFormat object SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("mm:ss") / / create time object Date date = new Date (finalI * 1000); / / execute time format and print the result System.out.println (simpleDateFormat.format (date));}}) } / / close the thread pool threadPool.shutdown () after the task is executed;}} this is the end of the article on "how java SimpleDateFormat converts local variables". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to convert local variables in java SimpleDateFormat". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Variables parts threads time knowledge programs tasks content objects formats articles security value single-line multiline examples easy to operate articles easy to understand more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft macOS MariaDB Shulou Tech Info Linux