当前位置: 首页>>代码示例>>Python>>正文


Python datetime.timezone方法代码示例

本文整理汇总了Python中datetime.datetime.timezone方法的典型用法代码示例。如果您正苦于以下问题:Python datetime.timezone方法的具体用法?Python datetime.timezone怎么用?Python datetime.timezone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在datetime.datetime的用法示例。


在下文中一共展示了datetime.timezone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __repr__

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def __repr__(self):
            """Convert to formal string, for repr().

            >>> tz = timezone.utc
            >>> repr(tz)
            'datetime.timezone.utc'
            >>> tz = timezone(timedelta(hours=-5), 'EST')
            >>> repr(tz)
            "datetime.timezone(datetime.timedelta(-1, 68400), 'EST')"
            """
            if self is self.utc:
                return "datetime.timezone.utc"
            if self._name is None:
                return "%s.%s(%r)" % (
                    self.__class__.__module__,
                    self.__class__.__name__,
                    self._offset,
                )
            return "%s.%s(%r, %r)" % (
                self.__class__.__module__,
                self.__class__.__name__,
                self._offset,
                self._name,
            ) 
开发者ID:sdispater,项目名称:tomlkit,代码行数:26,代码来源:_compat.py

示例2: test_normalize_tz_local

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def test_normalize_tz_local(self, timezone):
        # GH#13459
        with tm.set_timezone(timezone):
            rng = date_range('1/1/2000 9:30', periods=10, freq='D',
                             tz=tzlocal())

            result = rng.normalize()
            expected = date_range('1/1/2000', periods=10, freq='D',
                                  tz=tzlocal())
            tm.assert_index_equal(result, expected)

            assert result.is_normalized
            assert not rng.is_normalized

    # ------------------------------------------------------------
    # DatetimeIndex.__new__ 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_timezones.py

示例3: test_dti_tz_constructors

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def test_dti_tz_constructors(self, tzstr):
        """ Test different DatetimeIndex constructions with timezone
        Follow-up of GH#4229
        """

        arr = ['11/10/2005 08:00:00', '11/10/2005 09:00:00']

        idx1 = to_datetime(arr).tz_localize(tzstr)
        idx2 = pd.date_range(start="2005-11-10 08:00:00", freq='H', periods=2,
                             tz=tzstr)
        idx3 = DatetimeIndex(arr, tz=tzstr)
        idx4 = DatetimeIndex(np.array(arr), tz=tzstr)

        for other in [idx2, idx3, idx4]:
            tm.assert_index_equal(idx1, other)

    # -------------------------------------------------------------
    # Unsorted 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_timezones.py

示例4: test_dti_tz_constructors

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def test_dti_tz_constructors(self, tzstr):
        """ Test different DatetimeIndex constructions with timezone
        Follow-up of GH#4229
        """

        arr = ['11/10/2005 08:00:00', '11/10/2005 09:00:00']

        idx1 = to_datetime(arr).tz_localize(tzstr)
        idx2 = DatetimeIndex(start="2005-11-10 08:00:00", freq='H', periods=2,
                             tz=tzstr)
        idx3 = DatetimeIndex(arr, tz=tzstr)
        idx4 = DatetimeIndex(np.array(arr), tz=tzstr)

        for other in [idx2, idx3, idx4]:
            tm.assert_index_equal(idx1, other)

    # -------------------------------------------------------------
    # Unsorted 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:test_timezones.py

示例5: __init__

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def __init__(self, offset, name=None):
            """
            :param offset:
                A timedelta with this timezone's offset from UTC

            :param name:
                Name of the timezone; if None, generate one.
            """

            if not timedelta(hours=-24) < offset < timedelta(hours=24):
                raise ValueError('Offset must be in [-23:59, 23:59]')

            if offset.seconds % 60 or offset.microseconds:
                raise ValueError('Offset must be full minutes')

            self._offset = offset

            if name is not None:
                self._name = name
            elif not offset:
                self._name = 'UTC'
            else:
                self._name = 'UTC' + _format_offset(offset) 
开发者ID:tp4a,项目名称:teleport,代码行数:25,代码来源:util.py

示例6: create_timezone

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def create_timezone(offset):
    """
    Returns a new datetime.timezone object with the given offset.
    Uses cached objects if possible.

    :param offset:
        A datetime.timedelta object; It needs to be in full minutes and between -23:59 and +23:59.

    :return:
        A datetime.timezone object
    """

    try:
        tz = _timezone_cache[offset]
    except KeyError:
        tz = _timezone_cache[offset] = timezone(offset)
    return tz 
开发者ID:tp4a,项目名称:teleport,代码行数:19,代码来源:util.py

示例7: test_attributes

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def test_attributes():
    import datetime
    import osxphotos

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    photos = photosdb.photos(uuid=["15uNd7%8RguTEgNPKHfTWw"])
    assert len(photos) == 1
    p = photos[0]
    assert p.keywords == ["Kids"]
    assert p.original_filename == "Pumkins2.jpg"
    assert p.filename == "Pumkins2.jpg"
    assert p.date == datetime.datetime(
        2018, 9, 28, 16, 7, 7, 0, datetime.timezone(datetime.timedelta(seconds=-14400))
    )
    assert p.description == "Girl holding pumpkin"
    assert p.title == "I found one!"
    assert sorted(p.albums) == sorted(
        ["Pumpkin Farm", "AlbumInFolder", "Test Album (1)"]
    )
    assert p.persons == ["Katie"]
    assert p.path.endswith(
        "/tests/Test-10.14.6.photoslibrary/Masters/2019/07/27/20190727-131650/Pumkins2.jpg"
    )
    assert p.ismissing == False 
开发者ID:RhetTbull,项目名称:osxphotos,代码行数:26,代码来源:test_mojave_10_14_6.py

示例8: test_attributes

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def test_attributes():
    import datetime
    import osxphotos

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    photos = photosdb.photos(uuid=["D79B8D77-BFFC-460B-9312-034F2877D35B"])
    assert len(photos) == 1
    p = photos[0]
    assert p.keywords == ["Kids"]
    assert p.original_filename == "Pumkins2.jpg"
    assert p.filename == "D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg"
    assert p.date == datetime.datetime(
        2018, 9, 28, 16, 7, 7, 0, datetime.timezone(datetime.timedelta(seconds=-14400))
    )
    assert p.description == "Girl holding pumpkin"
    assert p.title == "I found one!"
    assert sorted(p.albums) == ["Pumpkin Farm", "Test Album"]
    assert p.persons == ["Katie"]
    assert p.path.endswith(
        "tests/Test-10.15.5.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg"
    )
    assert p.ismissing == False 
开发者ID:RhetTbull,项目名称:osxphotos,代码行数:24,代码来源:test_catalina_10_15_5.py

示例9: __eq__

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def __eq__(self, other):
            if type(other) != timezone:
                return False
            return self._offset == other._offset 
开发者ID:sdispater,项目名称:tomlkit,代码行数:6,代码来源:_compat.py

示例10: __eq__

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def __eq__(self, other):
            """
            Compare two timezones

            :param other:
                The other timezone to compare to

            :return:
                A boolean
            """

            if type(other) != timezone:
                return False
            return self._offset == other._offset 
开发者ID:tp4a,项目名称:teleport,代码行数:16,代码来源:util.py

示例11: tzname

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def tzname(self, dt):
            """
            :param dt:
                A datetime object; ignored.

            :return:
                Name of this timezone
            """

            return self._name 
开发者ID:tp4a,项目名称:teleport,代码行数:12,代码来源:util.py

示例12: tzinfo

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def tzinfo(self):
        """
        :return:
            If object is timezone aware, a datetime.tzinfo object, else None.
        """

        return self._y2k.tzinfo 
开发者ID:tp4a,项目名称:teleport,代码行数:9,代码来源:util.py

示例13: astimezone

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def astimezone(self, tz):
        """
        Convert this extended_datetime to another timezone.

        :param tz:
            A datetime.tzinfo object.

        :return:
            A new extended_datetime or datetime.datetime object
        """

        return extended_datetime.from_y2k(self._y2k.astimezone(tz)) 
开发者ID:tp4a,项目名称:teleport,代码行数:14,代码来源:util.py

示例14: test_attributes_2

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def test_attributes_2():
    """ Test attributes including height, width, etc """
    import datetime
    import osxphotos

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    photos = photosdb.photos(uuid=[UUID_DICT["has_adjustments"]])
    assert len(photos) == 1
    p = photos[0]
    assert p.keywords == ["wedding"]
    assert p.original_filename == "wedding.jpg"
    assert p.filename == "wedding.jpg"
    assert p.date == datetime.datetime(
        2019,
        4,
        15,
        14,
        40,
        24,
        86000,
        datetime.timezone(datetime.timedelta(seconds=-14400)),
    )
    assert p.description == "Bride Wedding day"
    assert p.title is None
    assert sorted(p.albums) == []
    assert p.persons == ["Maria"]
    assert p.path.endswith("Masters/2019/07/27/20190727-131650/wedding.jpg")
    assert not p.ismissing
    assert p.hasadjustments
    assert p.height == 1325
    assert p.width == 1526
    assert p.original_height == 1367
    assert p.original_width == 2048
    assert p.orientation == 1
    assert p.original_orientation == 1
    assert p.original_filesize == 460483 
开发者ID:RhetTbull,项目名称:osxphotos,代码行数:38,代码来源:test_mojave_10_14_6.py

示例15: test_date_invalid

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import timezone [as 别名]
def test_date_invalid():
    """ Test date is invalid """
    from datetime import datetime, timedelta, timezone
    import osxphotos

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    photos = photosdb.photos(uuid=[UUID_DICT["date_invalid"]])
    assert len(photos) == 1
    p = photos[0]
    delta = timedelta(seconds=p.tzoffset)
    tz = timezone(delta)
    assert p.date == datetime(1970, 1, 1).astimezone(tz=tz) 
开发者ID:RhetTbull,项目名称:osxphotos,代码行数:14,代码来源:test_mojave_10_14_6.py


注:本文中的datetime.datetime.timezone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。