package com.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
public class CommonUtils {
private static SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMMddHHddssSSS");//17
private static String date;
private static long num = 0L;
public static synchronized String getUUID() {
String s = UUID.randomUUID().toString();
return s.substring(0, 8) + s.substring(9, 13) + s.substring(14, 18) + s.substring(19, 23) + s.substring(24);
}
public static synchronized String getDatetimeStringSSS() {
String timeString = timeFormat.format(new Date());
if ((date == null) || (!date.equals(timeString))) {
date = timeString;
}
return date;
}
public static synchronized String getDatetimeString() {
String timeString = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
if ((date == null) || (!date.equals(timeString))) {
date = timeString;
}
return date;
}
public static synchronized String getDatetimeMD() {
String timeString = new SimpleDateFormat("MMdd").format(new Date());
if ((date == null) || (!date.equals(timeString))) {
date = timeString;
}
return date;
}
public static synchronized String getDatetimeJointNums() {
String str = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
if ((date == null) || (!date.equals(str))) {
date = str;
num = 100000L;
}
num += 1L;
String result = date + num;
return result;
}
public static void main(String[] args) {
System.out.println(getDatetimeMD());
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
public class CommonUtils {
private static SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMMddHHddssSSS");//17
private static String date;
private static long num = 0L;
public static synchronized String getUUID() {
String s = UUID.randomUUID().toString();
return s.substring(0, 8) + s.substring(9, 13) + s.substring(14, 18) + s.substring(19, 23) + s.substring(24);
}
public static synchronized String getDatetimeStringSSS() {
String timeString = timeFormat.format(new Date());
if ((date == null) || (!date.equals(timeString))) {
date = timeString;
}
return date;
}
public static synchronized String getDatetimeString() {
String timeString = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
if ((date == null) || (!date.equals(timeString))) {
date = timeString;
}
return date;
}
public static synchronized String getDatetimeMD() {
String timeString = new SimpleDateFormat("MMdd").format(new Date());
if ((date == null) || (!date.equals(timeString))) {
date = timeString;
}
return date;
}
public static synchronized String getDatetimeJointNums() {
String str = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
if ((date == null) || (!date.equals(str))) {
date = str;
num = 100000L;
}
num += 1L;
String result = date + num;
return result;
}
public static void main(String[] args) {
System.out.println(getDatetimeMD());
}
}