Java后端字符串转日期与日期转字符串

字符串转日期:

	public static Date strToDate(String str) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = null;
	   	try {
		   	date = format.parse(str);
	  	} catch (ParseException e) {
		   	e.printStackTrace();
	   	}
	   	return date;
	}

日期转字符串:

	public static String getFisrtDayOfMonth(Date date){

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String firstDayOfMonth = sdf.format(date.getTime());
	    
		return firstDayOfMonth;
	}

猜你喜欢

转载自blog.csdn.net/weixin_43992507/article/details/88420162