时间格式的转换日期转换毫秒

日期转换为毫秒

public  long changeDateToTime(String date) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String start=date;
        long longTime = 0;
    try {
            longTime=sdf.parse(start).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return longTime;
    }

毫秒转换为日期

public  String changeTimeToDate(long time) {
        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        long now = time;
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(now);
        return  formatter.format(calendar.getTime());
    }

毫秒转换为分钟

public  long changeTimeToMinutes(long time) {

         long minutes = (time % (1000 * 60 * 60)) / (1000 * 60);
         return minutes;
    }

你可能感兴趣的:(android)