on 01-18-2021 2:15 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
8 | |
8 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.