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;
	}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章