2017-06-14 63 views
-3

我必须做以下操作:获取当前时间和UTC转换串地龙

public long getDifference(String time) { 
    long diff = <CURRENT TIME IN UTC> - <PARAMETER TIME>; 

    return diff; 
} 

所以2个问题:

  1. 我怎样才能在UTC当前时间?
  2. 如何将字符串时间参数(格式yyyy-MM-dd HH:mm:ss)转换为长整型?
+1

'返回System.currentTimeMillis的() - new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”)。parse(time).getTime();' –

回答

0
  1. 使用System.currentTimeMillis()你可以得到本地时间
  2. 如果妳想要得到UTC时间,我认为你应该做的: current time - zone offset - daylight saving time
  3. 时间格式:new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(time).getTime()