Format a date or datetime into an ISO-8601 datetime string.

    Time is set to 00:00:00 for dates.

    Support dates before 1900.
761379
def to_iso_datetime(dt):
    '''
    
    '''
    if dt:
        date_str = to_iso_date(dt)
        time_str = '{dt.hour:02d}:{dt.minute:02d}:{dt.second:02d}'.format(
            dt=dt) if isinstance(dt, datetime) else '00:00:00'
        return 'T'.join((date_str, time_str))
272804
def datetime_string(time_zone=False):
    
    time = datetime.datetime.now()
    template = u"%04d-%02d-%02dT%02d:%02d:%02d"
    if time_zone:
        template += u"+00:00"
    return template % (
        time.year,
        time.month,
        time.day,
        time.hour,
        time.minute,
        time.second
    )
265281
def format_date(cls, timestamp):
        
        if not timestamp:
            raise DateTimeFormatterException('timestamp must a valid string {}'.format(timestamp))

        return timestamp.strftime(cls.DATE_FORMAT)
493297
def datetime_to_time(date, time):
    """"""
    if (255 in date) or (255 in time):
        raise RuntimeError("specific date and time required")

    time_tuple = (
        date[0]+1900, date[1], date[2],
        time[0], time[1], time[2],
        0, 0, -1,
        )
    return _mktime(time_tuple)
679407
public static String format( TimeZone timeZone, Date date ) {
        return format( DateFormat.DATE_FORMAT_STR_ISO8601, timeZone, date );
    }
855156
def format_datetime(date):
    
    # todo: test me
    if date.utcoffset() is None:
        return date.isoformat() + 'Z'

    utc_offset_sec = date.utcoffset()
    utc_date = date - utc_offset_sec
    utc_date_without_offset = utc_date.replace(tzinfo=None)
    return utc_date_without_offset.isoformat() + 'Z'
1211483
def parse_isotime(timestr):
    """"""
    try:
        return iso8601.parse_date(timestr)
    except iso8601.ParseError as e:
        raise ValueError(six.text_type(e))
    except TypeError as e:
        raise ValueError(six.text_type(e))
873467
def um_date_to_date(d):
    

    return datetime.datetime(year=d[0], month=d[1], day=d[2],
                             hour=d[3], minute=d[4], second=d[5])
946762
def iso_format_time(time)
      return time unless time.is_a? Time or time.is_a? Date
      time = time.getutc if time.is_a? Time
      time = time.new_offset(0) if time.is_a? DateTime
      time.strftime('%Y-%m-%dT%H:%M:%SZ')
    end
890367
private void sampleFormatDateTime() {
        List<String> text = new ArrayList<String>();
        DateTime now = DateTime.now();
        text.add("Show time: " + DateUtils.formatDateTime(this, now, DateUtils.FORMAT_SHOW_TIME));
        text.add("Show date: " + DateUtils.formatDateTime(this, now, DateUtils.FORMAT_SHOW_DATE));
        text.add("Numeric date: " + DateUtils.formatDateTime(this, now, DateUtils.FORMAT_NUMERIC_DATE));
        text.add("Show date (abbreviated): " + DateUtils.formatDateTime(this, now, DateUtils.FORMAT_SHOW_DATE
            | DateUtils.FORMAT_ABBREV_ALL));
        text.add("Show date and time: " + DateUtils.formatDateTime(this, now, DateUtils.FORMAT_SHOW_DATE
            | DateUtils.FORMAT_SHOW_TIME));
        text.add("Show date (force year): " + DateUtils.formatDateTime(this, now, DateUtils.FORMAT_SHOW_DATE
            | DateUtils.FORMAT_SHOW_YEAR));
        addSample("DateUtils.formatDateTime()", text);
    }
304689
def iso_string_to_python_datetime(
        isostring: str) -> Optional[datetime.datetime]:
    
    if not isostring:
        return None  # if you parse() an empty string, you get today's date
    return dateutil.parser.parse(isostring)
1207162
public static String formatTime(Date date) {
		if (null == date) {
			return null;
		}
		return DatePattern.NORM_TIME_FORMAT.format(date);
	}
1095260
def parse_date(date: str, hour_threshold: int = 200):
    
    # Format date string
    date = date.strip('Z')
    if len(date) == 4:
        date += '00'
    if not (len(date) == 6 and date.isdigit()):
        return
    # Create initial guess
    now = datetime.utcnow()
    guess = now.replace(day=int(date[0:2]),
                        hour=int(date[2:4]) % 24,
                        minute=int(date[4:6]) % 60,
                        second=0, microsecond=0)
    hourdiff = (guess - now) / timedelta(minutes=1) / 60
    # Handle changing months
    if hourdiff > hour_threshold:
        guess += relativedelta(months=-1)
    elif hourdiff < -hour_threshold:
        guess += relativedelta(months=+1)
    return guess
15606
def parse_time(time_input):
    
    if isinstance(time_input, datetime.date):
        return time_input.isoformat()  # datetime.date only returns date, datetime.datetime also returns time

    if len(time_input) < 8:
        raise ValueError('Invalid time string {}.\n'
                         'Please specify time in formats YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS'.format(time_input))
    time = dateutil.parser.parse(time_input)
    if len(time_input) <= 10:
        return time.date().isoformat()
    return time.isoformat()
371254
def format_datetime(self, value, format_):
        
        date_ = make_datetime(value)
        return dates.format_datetime(date_, format_, locale=self.lang)
694629
def _FormatDateTime(self, event):
    
    try:
      return timelib.Timestamp.CopyToIsoFormat(
          event.timestamp, timezone=self._output_mediator.timezone,
          raise_error=True)

    except (OverflowError, ValueError) as exception:
      self._ReportEventError(event, (
          'unable to copy timestamp: {0!s} to a human readable date and time '
          'with error: {1!s}. Defaulting to: "0000-00-00T00:00:00"').format(
              event.timestamp, exception))

      return '0000-00-00T00:00:00'
411810
protected static function convertDateTime($date)
    {
        if (!$date) {
            return;
        }

        $date = new \DateTime($date);
        $date->setTimezone(new \DateTimeZone(date_default_timezone_get()));

        return $date->format(\DateTime::ISO8601);
    }