本文整理汇总了Python中tastypie.serializers.Serializer.format_datetime方法的典型用法代码示例。如果您正苦于以下问题:Python Serializer.format_datetime方法的具体用法?Python Serializer.format_datetime怎么用?Python Serializer.format_datetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tastypie.serializers.Serializer
的用法示例。
在下文中一共展示了Serializer.format_datetime方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_format_datetime
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import format_datetime [as 别名]
def test_format_datetime(self):
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
serializer = Serializer(datetime_formatting='iso-8601')
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
serializer = Serializer(datetime_formatting='iso-8601-strict')
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33, 10)), '2010-12-16T02:31:33')
serializer = Serializer(datetime_formatting='rfc-2822')
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u'Thu, 16 Dec 2010 02:31:33 -0600')
serializer = Serializer(datetime_formatting='random-garbage')
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
with self.settings(TASTYPIE_DATETIME_FORMATTING='iso-8601'):
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
with self.settings(TASTYPIE_DATETIME_FORMATTING='iso-8601-strict'):
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33, 10)), '2010-12-16T02:31:33')
with self.settings(TASTYPIE_DATETIME_FORMATTING='rfc-2822'):
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u'Thu, 16 Dec 2010 02:31:33 -0600')
with self.settings(TASTYPIE_DATETIME_FORMATTING='random-garbage'):
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
示例2: test_format_datetime
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import format_datetime [as 别名]
def test_format_datetime(self):
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
serializer = Serializer(datetime_formatting='iso-8601')
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
serializer = Serializer(datetime_formatting='rfc-2822')
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u'Thu, 16 Dec 2010 02:31:33 -0600')
serializer = Serializer(datetime_formatting='random-garbage')
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
# Stow.
old_format = getattr(settings, 'TASTYPIE_DATETIME_FORMATTING', 'iso-8601')
settings.TASTYPIE_DATETIME_FORMATTING = 'iso-8601'
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
settings.TASTYPIE_DATETIME_FORMATTING = 'rfc-2822'
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u'Thu, 16 Dec 2010 02:31:33 -0600')
settings.TASTYPIE_DATETIME_FORMATTING = 'random-garbage'
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
# Restore.
settings.TASTYPIE_DATETIME_FORMATTING = old_format
示例3: test_format_datetime
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import format_datetime [as 别名]
def test_format_datetime(self):
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), "2010-12-16T02:31:33")
serializer = Serializer(datetime_formatting="iso-8601")
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), "2010-12-16T02:31:33")
serializer = Serializer(datetime_formatting="rfc-2822")
self.assertEqual(
serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u"Thu, 16 Dec 2010 02:31:33 -0600"
)
serializer = Serializer(datetime_formatting="random-garbage")
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), "2010-12-16T02:31:33")
# Stow.
old_format = getattr(settings, "TASTYPIE_DATETIME_FORMATTING", "iso-8601")
settings.TASTYPIE_DATETIME_FORMATTING = "iso-8601"
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), "2010-12-16T02:31:33")
settings.TASTYPIE_DATETIME_FORMATTING = "rfc-2822"
serializer = Serializer()
self.assertEqual(
serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u"Thu, 16 Dec 2010 02:31:33 -0600"
)
settings.TASTYPIE_DATETIME_FORMATTING = "random-garbage"
serializer = Serializer()
self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), "2010-12-16T02:31:33")
# Restore.
settings.TASTYPIE_DATETIME_FORMATTING = old_format
示例4: convert_date_time_to_tastypie
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import format_datetime [as 别名]
def convert_date_time_to_tastypie(self, dt):
serializer = Serializer()
return serializer.format_datetime(dt)