import time from django.utils import timezone from django.utils.translation import gettext as _ from rest_framework.response import Response from rest_framework.permissions import AllowAny from university.api.base import Endpoint class ServerTimeEndpoint(Endpoint): permission_classes = (AllowAny, ) def get(self, request, *args, **kwargs): now = timezone.localtime() now_str = now.strftime('%Y-%m-%d %H:%M:%S') now_timestamp = time.mktime(now.timetuple()) return Response({ 'detail': _('success'), 'data': { 'now': now_str, 'now_timestamp': now_timestamp } })