Creates sql datetime2 object from Python datetime object
        ignoring timezone
        @param pydatetime: Python datetime object
        @return: sql datetime2 object
503312
def from_pydatetime(cls, pydatetime):
        
        return cls(date=Date.from_pydate(pydatetime.date),
                   time=Time.from_pytime(pydatetime.time))
270655
def _build_date_time_time_zone(self, date_time):
        
        timezone = date_time.tzinfo.zone if date_time.tzinfo is not None else None
        return {
            self._cc('dateTime'): date_time.strftime('%Y-%m-%dT%H:%M:%S'),
            self._cc('timeZone'): get_windows_tz(timezone or self.protocol.timezone)
        }
1234097
def fromDatetime(klass, dtime):
        
        self = klass.__new__(klass)
        if dtime.tzinfo is not None:
            self._time = dtime.astimezone(FixedOffset(0, 0)).replace(tzinfo=None)
        else:
            self._time = dtime
        self.resolution = datetime.timedelta.resolution
        return self
102178
def parse_datetime(dt):
    ''''''
    d = datetime.strptime(dt[:-1], ISOFORMAT)

    if dt[-1:] == 'Z':
        return timezone('utc').localize(d)
    else:
        return d
1123340
def timestamp_with_timezone(dt=None):
    
    dt = dt or datetime.now()
    if timezone is None:
        return dt.strftime('%Y-%m-%d %H:%M%z')
    if not dt.tzinfo:
        tz = timezone.get_current_timezone()
        if not tz:
            tz = timezone.utc
        dt = dt.replace(tzinfo=timezone.get_current_timezone())
    return dt.strftime("%Y-%m-%d %H:%M%z")
1328463
def to_datetime(dt, tzinfo=None, format=None):
    
    if not dt:
        return dt
    
    tz = pick_timezone(tzinfo, __timezone__)
    
    if isinstance(dt, (str, unicode)):
        if not format:
            formats = DEFAULT_DATETIME_INPUT_FORMATS
        else:
            formats = list(format)
        d = None
        for fmt in formats:
            try:
                d = datetime.strptime(dt, fmt)
            except ValueError:
                continue
        if not d:
            return None
        d = d.replace(tzinfo=tz)
    else:
        d = datetime(getattr(dt, 'year', 1970), getattr(dt, 'month', 1),
            getattr(dt, 'day', 1), getattr(dt, 'hour', 0), getattr(dt, 'minute', 0),
            getattr(dt, 'second', 0), getattr(dt, 'microsecond', 0))
        if not getattr(dt, 'tzinfo', None):
            d = d.replace(tzinfo=tz)
        else:
            d = d.replace(tzinfo=dt.tzinfo)
    return to_timezone(d, tzinfo)
179729
public T toDateTime(String dateTime, String timeZoneId) {
    return toDateTime(ISODateTimeFormat.dateHourMinuteSecond().parseDateTime(dateTime)
        .withZoneRetainFields(DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZoneId))));
  }
18018
def fromJD(jd, utcoffset):
        
        if not isinstance(utcoffset, Time):
            utcoffset = Time(utcoffset)
        localJD = jd + utcoffset.value / 24.0
        date = Date(round(localJD))
        time = Time((localJD + 0.5 - date.jdn) * 24)
        return Datetime(date, time, utcoffset)
128003
def timestamp_from_datetime(dt):
    
    try:
        utc_dt = dt.astimezone(pytz.utc)
    except ValueError:
        utc_dt = dt.replace(tzinfo=pytz.utc)
    return timegm(utc_dt.timetuple())
774926
def to_pydatetime(self):
        
        dt = datetime.datetime.combine(self._date.to_pydate(), self._time.to_pytime())
        from .tz import FixedOffsetTimezone
        return dt.replace(tzinfo=_utc).astimezone(FixedOffsetTimezone(self._offset))
454056
public static java.sql.Timestamp convertSqlDate(Date dt) {
        if (dt == null) {
            return new java.sql.Timestamp(0);
        }
        return new java.sql.Timestamp(dt.getTime());
    }
225983
def yeardoy2datetime(yeardate: int,
                     utsec: Union[float, int] = None) -> datetime.datetime:
    
    if isinstance(yeardate, (tuple, list, np.ndarray)):
        if utsec is None:
            return np.asarray([yeardoy2datetime(y) for y in yeardate])
        elif isinstance(utsec, (tuple, list, np.ndarray)):
            return np.asarray([yeardoy2datetime(y, s) for y, s in zip(yeardate, utsec)])

    yeardate = int(yeardate)

    yd = str(yeardate)
    if len(yd) != 7:
        raise ValueError('yyyyddd expected')

    year = int(yd[:4])
    assert 0 < year < 3000, 'year not in expected format'

    dt = datetime.datetime(year, 1, 1) + datetime.timedelta(days=int(yd[4:]) - 1)
    assert isinstance(dt, datetime.datetime)

    if utsec is not None:
        dt += datetime.timedelta(seconds=utsec)

    return dt
1278607
def generate_rfc3339(d, local_tz=True):
    
    try:
        if local_tz:
            d = datetime.datetime.fromtimestamp(d)
        else:
            d = datetime.datetime.utcfromtimestamp(d)
    except TypeError:
        pass

    if not isinstance(d, datetime.date):
        raise TypeError('Not timestamp or date object. Got %r.' % type(d))

    if not isinstance(d, datetime.datetime):
        d = datetime.datetime(*d.timetuple()[:3])

    return ('%04d-%02d-%02dT%02d:%02d:%02d%s' %
            (d.year, d.month, d.day, d.hour, d.minute, d.second,
             _generate_timezone(d, local_tz)))
729563
def _try_pydatetime(x):
    
    try:
        # for datetimeindex
        x = [y.isoformat() for y in x.to_pydatetime()]
    except AttributeError:
        pass
    try:
        # for generic series
        x = [y.isoformat() for y in x.dt.to_pydatetime()]
    except AttributeError:
        pass
    return x
448047
def from_db_value(self, value, expression, connection, context):
        
        # log.debug("from_db_value: {}, {}", value, type(value))
        if value is None:
            return value
        if value == '':
            return None
        return iso_string_to_python_datetime(value)
1204504
def dtstr_to_datetime(dtstr, to_tz=None, fail_silently=True):
    
    try:
        dt = datetime.datetime.utcfromtimestamp(int(dtstr, 36) / 1e3)
        if to_tz:
            dt = timezone.make_aware(dt, timezone=pytz.UTC)
            if to_tz != pytz.UTC:
                dt = dt.astimezone(to_tz)
        return dt
    except ValueError, e:
        if not fail_silently:
            raise e
        return None
351134
def str2dt(time: datetime) -> np.ndarray:
    
    if isinstance(time, datetime):
        return time
    elif isinstance(time, str):
        return parse(time)
    elif isinstance(time, np.datetime64):
        return time.astype(datetime)
    else:  # some sort of iterable
        try:
            if isinstance(time[0], datetime):
                return time
            elif isinstance(time[0], np.datetime64):
                return time.astype(datetime)
            elif isinstance(time[0], str):
                return [parse(t) for t in time]
        except (IndexError, TypeError):
            pass

        # last resort--assume pandas/xarray

        return time.values.astype('datetime64[us]').astype(datetime)