Android Format date with time zone

前端 未结 8 1371
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 13:05

I need to format the date into a specific string.

I used SimpleDateFormat class to format the date using the pattern \"yyyy-MM-dd\'T\'HH:m

8条回答
  •  悲&欢浪女
    2020-12-10 13:46

    If you want the date for a different timeZone (which the title suggests)

      val nowMillsUTC = System.currentTimeMillis()
    
      val timeZoneID = "Australia/Perth"
      val tz = TimeZone.getTimeZone(timeZoneID)
    
      val simpleDateFormat = SimpleDateFormat("HH.mm  dd.MMM.yyyy", Locale.getDefault())
      simpleDateFormat.setTimeZone(tz)
      val resultTxt = simpleDateFormat.format(nowMillsUTC)
    
      print(timeZoneID + " -> " + resultTxt)
      //   Australia/Perth -> 19.59  21.Mar.2019
    

提交回复
热议问题