本文整理匯總了Python中django.utils.dateformat.DateFormat方法的典型用法代碼示例。如果您正苦於以下問題:Python dateformat.DateFormat方法的具體用法?Python dateformat.DateFormat怎麽用?Python dateformat.DateFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.utils.dateformat
的用法示例。
在下文中一共展示了dateformat.DateFormat方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: entries_by_date
# 需要導入模塊: from django.utils import dateformat [as 別名]
# 或者: from django.utils.dateformat import DateFormat [as 別名]
def entries_by_date(self, request, year, month=None, day=None, *args, **kwargs):
self.entries = self.get_entries().filter(date__year=year)
self.search_type = _('date')
self.search_term = year
if month:
self.entries = self.entries.filter(date__month=month)
df = DateFormat(date(int(year), int(month), 1))
self.search_term = df.format('F Y')
if day:
self.entries = self.entries.filter(date__day=day)
self.search_term = date_format(date(int(year), int(month), int(day)))
return Page.serve(self, request, *args, **kwargs)
示例2: test_multitenant_chat_consumer
# 需要導入模塊: from django.utils import dateformat [as 別名]
# 或者: from django.utils.dateformat import DateFormat [as 別名]
def test_multitenant_chat_consumer():
settings.CHANNEL_LAYERS = TEST_CHANNEL_LAYERS
client, room, user = prepare_room_and_user()
communicator = WebsocketCommunicator(
multitenant_application, f"/ws/django_chatter/chatrooms/{room.id}/",
headers=[
(
b'cookie',
f'sessionid={client.cookies["sessionid"].value}'.encode('ascii')
),
(b'host', b'localhost:8000')]
)
connected, subprotocol = await communicator.connect()
assert connected
data = {
'message_type': 'text',
'message': "Hello!",
'sender': user.username,
'room_id': str(room.id),
}
await communicator.send_json_to(data)
response = await communicator.receive_json_from()
response = response
message = Message.objects.all()[0]
time = message.date_created
# zone = pytz.timezone(get_default_timezone_name())
# time = time.astimezone(tz=zone)
# formatted = dateformat.DateFormat(time)
# time = formatted.format('M d, Y h:i a')
assert response['message_type'] == 'text'
assert response['message'] == 'Hello!'
assert response['sender'] == 'user0'
assert response['room_id'] == str(room.id)
assert response['date_created'] == time.strftime("%d %b %Y %H:%M:%S %Z")
await communicator.disconnect()