当前位置:网站首页>How to generate unique file names

How to generate unique file names

2022-07-07 23:16:00 codepig16

Mode one

Generate a five digit random number plus the month, day, minute and second of the current time

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class MyUtil {
    
    public static void main(String[] args) {
    
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        Random random = new Random();
        String unique = random.nextInt(89999 + 10000) + simpleDateFormat.format(new Date());
        System.out.println(unique);
    }
}
原网站

版权声明
本文为[codepig16]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130559466675.html