android日期格式时间戳输出为" /日期(1393346946000 + 0200)/

时间:2014-04-03 14:29:40

标签: android date timestamp

我想像这种格式转换当前时间:

" /日期(1393346946000 + 0200)/

我该怎么做?

 public static Date getCurrentTime() {
        Calendar c = Calendar.getInstance();
        System.out.println("Current time => " + c.getTimeInMillis());
        long time = (System.currentTimeMillis());

        System.out.println("Current time2 => " + time);
        Date currentTime = c.getTime();
        return
                currentTime;

    }

1 个答案:

答案 0 :(得分:0)

使用此选项可将当前时间转换为所需格式...

String inputPattern = "yyyy-MM-dd hh:mm:ss";
    String outputPattern = "dd/MM";//here you can give your output format that's all

    SimpleDateFormat inFormat = new SimpleDateFormat(inputPattern);
    SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern);
    Date date1 = null;

    if (date != null) {
        try {
            date1 = inFormat.parse(date);
            str = outputFormat.format(date1);
            Log.d(null, str);
        } catch (ParseException e) {
            e.printStackTrace();
        }

    } else {
        str = " ";
    }