DateTimeToXSDateTime static method

String DateTimeToXSDateTime(
  1. DateTime dateTime
)
Dates the DateTime into an XML schema date time. The date time.

Implementation

static String DateTimeToXSDateTime(DateTime dateTime) {
  String value = DateFormat("yyyy-MM-ddTHH:mm:ss").format(dateTime);
  if (dateTime.millisecond != 0) {
    value += ".${dateTime.millisecond.toString().padLeft(3, '0')}";
  }
  if (dateTime.isUtc) {
    return "${value}Z";
  } else if (dateTime is TZDateTime) {
    return "$value${_FormatOffset(dateTime.timeZoneOffset)}";
  } else {
    return value;
  }

  //            switch (dateTime.Kind)
  //            {
  //                case DateTimeKind.Utc:
  //                    format += "Z";
  //                    break;
  //                case DateTimeKind.Local:
  //                    format += "zzz";
  //                    break;
  //                default:
  //                    break;
  //            }
  //
  //            // Depending on the current culture, DateTime formatter will replace ':' with
  //            // the DateTimeFormatInfo.TimeSeparator property which may not be ':'. Force the proper string
  //
  //            return dateTime.ToString(format, CultureInfo.InvariantCulture);
}