标签:ati form ring ace pattern int turn str catch
public class DateOrStringUtil { //日期转为字符串,默认yyyy-MM-dd public static String dateToString(Date d) { return dateToString(d, "yyyy-MM-dd"); } //日期转为字符串,自定义格式 public static String dateToString(Date d, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); return sdf.format(d); } //字符串转为日期,默认yyyy-MM-dd public static Date stringToDate(String str) { return stringToDate(str, "yyyy-MM-dd"); } //字符串转为日期,自定义格式 public static Date stringToDate(String str, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); try { Date d = sdf.parse(str); return d; } catch (ParseException e) { e.printStackTrace(); } return new Date(); } }
标签:ati form ring ace pattern int turn str catch
原文地址:http://www.cnblogs.com/by-1642146903/p/7078311.html