我想獲取其他時區的時期和時間,比如我人在香港,如何獲取美國的時間?
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss z");
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
sdf.format(calendar.getTime());
不知道怎麼獲取年和月。謝謝幫忙
試試:
Calendar calendar = Calendar.getInstance();
Calendar LATime = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));
LATime.setTimeInMillis(calendar.getTimeInMillis());
int year = LATime.get(Calendar.YEAR);
int month = LATime.get(Calendar.MONTH);
int date = LATime.get(Calendar.DATE);