package com.help; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * 时间处理工具类 * * */ public final class MyDate { /** * 生成当前时间 格式为 xxxx/xx/xx xx:xx:xx * */ public static String getNowTime1(){ Date now=new Date(); SimpleDateFormat format=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); String time=format.format(now); return time; } /** * 生成当前时间 格式为 xxxx年xx月xx日 xx时xx分xx秒 * */ public static String getNowTime2(){ Date now=new Date(); SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒"); String time=format.format(now); return time; } /** * 生成当前日期 格式为 xxxx年xx月xx日 * */ public static String getNowDate1(){ Calendar c=Calendar.getInstance(); int year=c.get(Calendar.YEAR); int month=c.get(Calendar.MONTH); int date=c.get(Calendar.DATE); String str=year+"年"+month+"月"+date+"日"; return str; } public static String getNowDate2(){ Calendar c=Calendar.getInstance(); int year=c.get(Calendar.YEAR); int month=c.get(Calendar.MONTH); int date=c.get(Calendar.DATE); String str=year+"/"+month+"/"+date; return str; } }
java中常用的时间工具类_java中常用的时间工具类整理
最新推荐文章于 2022-09-21 18:10:43 发布