Get current time in a given timezone : android

后端 未结 10 1967
悲哀的现实
悲哀的现实 2020-11-30 10:13

I am new to Android and I am currently facing an issue to get current time given the timezone.

I get timezone in the format \"GMT-7\" i.e. string. and I have the sys

10条回答
  •  迷失自我
    2020-11-30 10:41

    Try this:

    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    df.setTimeZone(TimeZone.getTimeZone("YOUR_TIMEZONE"));
    String strDate = df.format(date);
    

    YOUR_TIMEZONE may be something like: GMT, UTC, GMT-5, etc.

提交回复
热议问题