Java 获取时间毫秒数并格式化

package com.hualanhai.datatime;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

public class ShowTime {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
//      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//      String startTime = sdf.format(startTime);
//      SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd' 'HH:mm");
        String starTime = sdf.format(new Date());
        System.out.println(starTime);
        String[] strs = starTime.split(" ");
        String resString = Arrays.toString(strs);
        System.out.println(resString);
        System.out.println(strs[0]);
        //获取当前时间毫秒数
        java.util.Date savetime = new java.util.Date();
        System.out.println("当前时间毫秒数字"+savetime.getTime());
        //毫秒数格式为当前时间
//        long sd=1345185923140L;  
//        Date dat=new Date(sd);  
//        GregorianCalendar gc = new GregorianCalendar();   
//        gc.setTime(dat);  
//        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  
//        String sb=format.format(gc.getTime());  
//        System.out.println(sb);  
        Date dattimeDate = new Date(savetime.getTime());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(dattimeDate);
        SimpleDateFormat formattwo = new SimpleDateFormat("yyyy/MM/dd' 'HH:mm");
        String nowtime = formattwo.format(calendar.getTime());
        System.out.println("当前已经格式化的时间"+nowtime);

    }

}

你可能感兴趣的:(android,java,Calendar)