Operación de formateo de fecha / hora

Formatee y envíe la fecha y hora actuales

		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); //指定日期格式
		SimpleDateFormat sdf1 = new SimpleDateFormat("HHmmss");  //指定时间格式
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd:HHmmss");  //指定日期、时间格式
		Calendar cal = Calendar.getInstance();            //获取当前日期、时间
		String curDate = null;
		String curtime = null;
		String date = null;
        
        date = sdf2.format(cal.getTime);  //格式化输入时间
		curtime = sdf1.format(cal.getTime());   //格式化输出时间
		curDate = sdf.format(cal.getTime());  //格式化输出日期
Obtenga la hora o fecha en unos pocos días u horas
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat sdf1 = new SimpleDateFormat("HHmmss");
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd:HHmmss");
		Calendar cal = Calendar.getInstance();
		String curDate = null;
		String curtime = null;
		String date = null;
		
		cal.add(Calendar.DATE, Integer.parseInt(validTime)); //当前几天后或几天前(例2或者-2)日期,参数2为对应天数
		cal.add(Calendar.HOUR, Integer.parseInt(validTime)); //几小时候或者几小时前,参数2为对应小时数
		curtime = sdf1.format(cal.getTime());  
		curDate = sdf.format(cal.getTime());
		date = sdf2.format(cal.getTime);
Obtener marca de tiempo actual

long timeFlag = System.currentTimeMillis();
Obtenga la marca de fecha y hora especificada

public static void main(String[] arg) throws ParseException{
     SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
     Date date=simpleDateFormat .parse("2010-06-25");
     int timeStemp = date.getTime();
     System.out.println(timeStemp );
}




20 artículos originales publicados · Me gusta6 · Visitas 10,000+

Supongo que te gusta

Origin blog.csdn.net/weixin_36662608/article/details/71142590
Recomendado
Clasificación