Code example for SimpleDateFormat

Methods: applyPattern, format

0
        return sdf.format(new Date(time_seconds * 1000));
    } 
     
    @SuppressLint("SimpleDateFormat") 
	public static String time_string(long time_seconds){
        SimpleDateFormat sdf = new SimpleDateFormat();
        sdf.applyPattern("HH:mm");
        return sdf.format(new Date(time_seconds * 1000));
    } 
     
	@SuppressLint("SimpleDateFormat") 
	public static String friendly_time_string(long time_seconds) {
		Date date = new Date(time_seconds * 1000);
		Date now = new Date();
		 
		// 如果不是当年的,显示年份 
		if ( now.getYear() != date.getYear() ){
			return (date.getYear() + 1900) + "年";
		} 
		 
		// 是当年的,显示可读的日期,或时间,或x分钟前