根据时区获取时间的方法

   // 获得的formatter
        DateFormat formatter = DateFormat.getDateTimeInstance();
        TimeZone timezone = TimeZone.getTimeZone("Asia/Tokyo");
//设置DateFormat的时区 

   formatter.setTimeZone(timezone);
        // 获得格式化后的时间
        String dateTime = formatter.format(new Date());
        System.out.println(dateTime);

 

 

 

 

 

 

 

Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Japan"));
        System.out.println(calendar.get(calendar.YEAR));
        // calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH),
        // calendar.get(calendar.HOUR_OF_DAY), calendar.get(calendar.MINUTE));
        Date date = new Date(calendar.get(Calendar.YEAR) - 1900, calendar.get(Calendar.MONTH),
                             calendar.get(Calendar.DAY_OF_MONTH), calendar.get(calendar.HOUR_OF_DAY),
                             calendar.get(calendar.MINUTE));

你可能感兴趣的:(java,ruby,运维)