cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Date in GMT

jayesh040583
Explorer
0 Kudos

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.

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Hi jayesh040583,

You don't need to subtract the time manually, please find below the code which would provide you time in two time zones. By default the system provides date time in UTC.

import java.util.TimeZone;
import java.util.HashMap;
import static java.util.Calendar.*;

def AusTimeZone = TimeZone.getTimeZone('Australia/Melbourne');
def cal = Calendar.instance;
def date = cal.time;
def dateFormat = 'dd-MM-yyyy\'T\'HH:mm:ss';
def IstTimeZone = TimeZone.getTimeZone('IST');

println(date.format(dateFormat, AusTimeZone))
println(date.format(dateFormat, IstTimeZone))

Hope this helps!

thanks and regards,

Praveen T

jayesh040583
Explorer
0 Kudos

Hi Praveen,

Thank you for responding.

Actually, I am getting the date from the source system. It can be any backdated date. In this case how we can convert the incoming date into GMT.

Jayesh.