8시간 이상 걸리는 문제 해결

5655 단어 code
1. 날짜와 시간을 얻는다
    /**
     *  、  、  
     * day :01 01   week:        time:  08:00
     * @param time         
     * @return
     */
    public static String[] getDate(long time) {
        Date date = new Date(time);
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM dd ");
        SimpleDateFormat weekFormat = new SimpleDateFormat("EEEE");
        SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
        String day = dateFormat.format(date);
        String week = weekFormat.format(date);
        String tim = timeFormat.format(date);
        String[] dateStr = new String[]{day, week, tim};
        Log.e("MyLog", "DateUtil.getDate:       : --->>> " + day + "  " + week + "  " + tim);
        return dateStr;
    }

인쇄 결과
01-13 17:35:25.878 18213-18326/com.pa.paperless E/MyLog: DateUtil.getDate:       : --->>> 01 14        01:35

2. 시간대 문제 해결, 지금보다 8시간 더
    /**
     * @param time      
     *      :SimpleDateFormat  .setTimeZone(TimeZone.getTimeZone("GTM"));
     * @return String id = TimeZone.getDefault().getID();
     */
    public static String[] getGTMDate(long time) {
        Date tTime = new Date(time);

        SimpleDateFormat day = new SimpleDateFormat("MM dd ");
        day.setTimeZone(TimeZone.getTimeZone("GTM"));
        String dayt = day.format(tTime);

        SimpleDateFormat week = new SimpleDateFormat("E");
        week.setTimeZone(TimeZone.getTimeZone("GTM"));
        String weekt = week.format(tTime);

        SimpleDateFormat tim = new SimpleDateFormat("HH:mm");
        tim.setTimeZone(TimeZone.getTimeZone("GTM"));
        String timt = tim.format(tTime);

        String[] date = {dayt, weekt, timt};
        Log.e("MyLog", "DateUtil.getGTMDate:       --->>> " + dayt + "  " + weekt + "  " + timt);
        return date;
    }

인쇄 결과
01-13 17:35:25.878 18213-18326/com.pa.paperless E/MyLog: DateUtil.getGTMDate:       --->>> 01 13       17:35

좋은 웹페이지 즐겨찾기