Hi friends, recently I got chance to write a code to convert Utc date time to iso 8601. I wrote following code snippet you can modify as per your need
public static str GetEPochTime(utcdatetime _DateTimeValue)
{
utcDateTime utcDateTimeValue;
str formattedDateTime;
date datepart;
int milliseconds;
TimeOfDay _time;
// _DateTimeValue = DateTimeUtil::applyTimeZoneOffset(_DateTimeValue, Timezone::GMTPLUS0300KUWAIT_RIYADH); // Adjust for specific timezone if needed
int _year= DateTimeUtil::year(_DateTimeValue);
int _day = DateTimeUtil::day(_DateTimeValue);
int _Month = DateTimeUtil::month(_DateTimeValue);
int _Hour = DateTimeUtil::hour(_DateTimeValue);
int _second = DateTimeUtil::second(_DateTimeValue);
int _minute = DateTimeUtil::minute(_DateTimeValue);
int _timetomilliSecond = 0;
var localTime = new System.DateTime(_year, _Month, _day, _Hour, _minute, _second,_timetomilliSecond, System.DateTimeKind::Utc);
localTime =System.TimeZoneInfo::ConvertTime(localTime,System.TimeZoneInfo::FindSystemTimeZoneById("Arabic Standard Time"));
// Example UTC DateTime
// utcDateTimeValue = _DateTimeValue;
formattedDateTime = localTime.ToString("o");
// formattedDateTime =DateTimeUtil::toStr(_DateTimeValue);
formattedDateTime =strReplace(formattedDateTime,".0000000",".00+03:00");
return formattedDateTime;