1.把播放时长的毫秒转为分和秒
比如:传过去的时间毫秒是5000,则返回 00 05
GregorianCalendar gc = new GregorianCalendar(); LogUtils.debug("当前播放的位置"+player.getCurrentPosition()); gc.setTimeInMillis(player.getCurrentPosition() + 1000); SimpleDateFormat sdf = new SimpleDateFormat("mm:ss"); LogUtils.debug("gc.format"+gc.getTime());
常用的日期转换,比如把 2016-02-12这样的转换为时间戳传给服务器
可以这样
/** * 把字符串类型的日期 比如2016-01-20转为时间戳 * * @param dateString * @return * @throws ParseException */ public static long parseDateToLong(String dateString){ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = simpleDateFormat.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } LogUtils.debug("parseDate==" + date.getTime()); return date.getTime(); }
然后还有把另类型的时间戳转为具体的时间,方法是一样的
/** * 获取一个时间的字符串,格式如下:"yyMM" * * @return 返回如:06:09 */ public static String getSimpleDateYYMMDD(long data) { return new SimpleDateFormat("yy:MM-dd").format(new Date(data)); }
这些事java.text包下面的方法,还有一种是用apache的,以后再说