java工具类10-时间工具类

public class DateUtil {
//时间毫秒转日期格式 public static String longToDate(String s) { long milliSecond = Long.valueOf(s).longValue(); Date date = new Date(); date.setTime(milliSecond); String format = new SimpleDateFormat("yyyyMMdd").format(date); return format; } //创建日期文件夹 public static String createFileBySysTime(String path) { // 1. 读取系统时间 Calendar calendar = Calendar.getInstance(); Date time = calendar.getTime(); // 2. 格式化系统时间 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); //获取系统当前时间并将其转换为string类型,fileName即文件名 String fileName = format.format(time); // 3. 创建文件夹 String newPath = path + fileName; File file = new File(newPath); //如果文件目录不存在则创建目录 if (!file.exists()) { if (!file.mkdir()) { System.out.println(newPath+": Current path does not exist, creation failed"); return null; } } //System.out.println("创建成功" + newPath); return newPath; } }
原文地址:https://www.cnblogs.com/chong-zuo3322/p/12855413.html