The value in parenthesis appears to be epoch seconds, that is, seconds since 12:00 AM Jan 1, 1970, and the value after the +
sign looks like a timezone offset. We can convert epoch seconds to a Datetime using Datetime.newInstance(Long seconds)
, and just take the date part from the result. This method expects a GMT value, which is what the portion before the +
sign should be, so we should be able to ignore the GMT offset, however, you should test with real values from your data to determine if you need to incorporate it.
Given this approach, we can just strip out the epoch seconds, convert to date time, and convert to date:
string dstr = 'Date(1617145200000+0100)';
string secs = dstr.split('\\(')[1].split('\\+')[0]; // pull out the seconds
system.debug(secs);
Datetime dt = Datetime.newInstance(Long.valueOf(secs));
Date result = dt.date();
system.debug(result);
Using this approach, the date value in the example is 30 March 2021.