Skip to Content
0
Jan 18, 2021 at 02:15 AM

Convert Date in GMT

178 Views

Hello Guys,

Hope you all are doing good.

I am working on one interface development in which I am getting a date (without timestamp) from SAP. In CPI I am adding the Australian current time. Now, I am trying to convert this date and time into GMT.

e.g. The date is 17-01-2021 09:00:00 (Australian timezone) needs to be converted as 16-01-2021 23:00:00 (GMT).

I tried to write a script but it is not working as expected. Can anyone help me in getting the correct output.

Many thanks.

import java.util.TimeZone; 
import groovy.time.TimeCategory
def Autime = "";
def timzn = TimeZone.getTimeZone("Australia/Melbourne")
def ts = new Date() 
Autime = (ts.format("yyyy-MM-dd HH:mm:ss", timezone=timzn)) 
def curDateTime3 = new Date().parse("yyyy-MM-dd HH:mm:ss", Autime)
println Autime
println curDateTime3 use( TimeCategory ) {
    inGMT = Autime - 11.hours
}  
println inGMT 

Jayesh.