国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

四、java-常用時間轉換

2019-11-06 07:18:15
字體:
來源:轉載
供稿:網友

四、java-常用時間轉換

時間轉換和獲取時間是我們常用到的東西我自己就寫了很多方法,你們也可以自己寫個工具類將方法放入其中

源碼如下:在任何類只需你的工具類名點方法即可

/**	 * 方法描述:字符串轉時間 格式:yyyy-MM-dd	 *@param s	 *@return	 *@throws ParseException	 */	public static Date StrConDate_ymd(String s) throws ParseException {		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(				"yyyy-MM-dd");		Date date = new Date();		date = sdf.parse(s);		return date;	}	/**	 * 方法描述:字符串轉時間 格式:yyyy-MM-dd HH	 *@param s	 *@return	 *@throws ParseException	 */	public static Date StrConDate_ymdh(String s) throws ParseException {		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(				"yyyy-MM-dd HH");		Date date = new Date();		date = sdf.parse(s);		return date;	}	/**	 * 方法描述:字符串轉時間 格式:yyyy-MM-dd HH:mm	 *@param s	 *@return	 *@throws ParseException	 */	public static Date StrConDate_ymdhm(String s) throws ParseException {		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(				"yyyy-MM-dd HH:mm");		Date date = new Date();		date = sdf.parse(s);		return date;	}	/**	 * 方法描述:字符串轉時間 格式:yyyy-MM-dd HH:mm:ss	 *@param s	 *@return	 *@throws ParseException	 */	public static Date StrConDate_ymdhms(String s) throws ParseException {		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(				"yyyy-MM-dd HH:mm:ss");		Date date = new Date();		date = sdf.parse(s);		return date;	}	/**	 * 方法描述:時間轉字符串 格式:yyyy-MM-dd	 *@param d	 *@return	 */	public static String DateConStr_ymd(Date d) {		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(				"yyyy-MM-dd");		return sdf.format(d);	}	/**	 * 方法描述:時間轉字符串 格式:yyyy年MM月dd日	 *@param d	 *@return	 */	public static String DateConStr_ymd1(Date d) {		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(				"yyyy年MM月dd日");		return sdf.format(d);	}	/**	 * 方法描述:獲取時間   類型Date	 *@return	 */	public static Date GainDate() {		Date date=new Date();		return date;	}	/**	 * 方法描述:獲取時間   類型String 格式yyyy-MM-dd HH:mm:ss	 *@return	 */	public static String GainDate_ymdhms() {		Date date=new Date();		DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");		String time=format.format(date);		return time;	}	/**	 * 方法描述:獲取時間   類型String 格式yyyy-MM-dd HH:mm	 *@return	 */	public static String GainDate_ymdhm() {		Date date=new Date();		DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm");		String time=format.format(date);		return time;	}	/**	 * 方法描述:獲取時間   類型String 格式yyyy-MM-dd HH	 *@return	 */	public static String GainDate_ymdh() {		Date date=new Date();		DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH");		String time=format.format(date);		return time;	}	/**	 * 方法描述:獲取時間   類型String 格式yyyy-MM-dd	 *@return	 */	public static String GainDate_ymd() {		Date date=new Date();		DateFormat format=new SimpleDateFormat("yyyy-MM-dd");		String time=format.format(date);		return time;	}	/**	 * 方法描述:獲取時間   類型String 格式yyyy年MM月dd日 HH時mm分ss秒	 *@return	 */	public static String GainDate_Charymdhms() {		Date date=new Date();		DateFormat format=new SimpleDateFormat("yyyy年MM月dd日 HH時mm分ss秒");		String time=format.format(date);		return time;	}	/**	 * 方法描述:獲取時間   類型String 格式yyyy年MM月dd日 HH時mm分	 *@return	 */	public static String GainDate_Charymdhm() {		Date date=new Date();		DateFormat format=new SimpleDateFormat("yyyy年MM月dd日 HH時mm分");		String time=format.format(date);		return time;	}	/**	 * 方法描述:獲取時間   類型String 格式yyyy年MM月dd日 HH時	 *@return	 */	public static String GainDate_Charymdh() {		Date date=new Date();		DateFormat format=new SimpleDateFormat("yyyy年MM月dd日 HH時");		String time=format.format(date);		return time;	}	/**	 * 方法描述:獲取時間   類型String 格式yyyy年MM月dd日	 *@return	 */	public static String GainDate_Charymd() {		Date date=new Date();		DateFormat format=new SimpleDateFormat("yyyy年MM月dd日 ");		String time=format.format(date);		return time;	}	/**	 * 方法描述:去掉:,-,用于時間字符串去除符號	 *@param s	 *@return	 */	public static String delsign(String s) {		s=s.replaceAll(":|-|//s", "");		return s;	}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 通辽市| 泊头市| 定南县| 三穗县| 句容市| 额济纳旗| 高尔夫| 江达县| 得荣县| 华安县| 昭觉县| 新巴尔虎右旗| 化州市| 咸阳市| 双柏县| 南川市| 阜阳市| 乃东县| 资阳市| 龙川县| 宜兰市| 屯门区| 麻城市| 台前县| 古丈县| 克什克腾旗| 昌宁县| 东源县| 青龙| 南郑县| 淳化县| 镇宁| 吉首市| 宜城市| 滦平县| 白河县| 宁蒗| 额敏县| 化州市| 桓仁| 滁州市|