1

I'm having difficulty converting this timestamp value to local time using the template tags provided in the Django documentation:

 {% load tz %}
 {% get_current_timezone as TIME_ZONE %}
 {{ private_message.timestamp|timezone:TIME_ZONE|date:'m/d/Y: h:i a' }}

I've tried many different template tags include load localtime and others. Regardless, the time still displays as UTC.

Settings:

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

And I'm saving the timestamp as timezone.now() in my views.py

Any help would be greatly appreciated. Thanks!

winston
  • 3,000
  • 11
  • 44
  • 75

1 Answers1

0

The point is, your timezone is still set to UTC.

TIME_ZONE = 'UTC'

So, for something like UTC+2, you can use

TIME_ZONE = 'Europe/Istanbul'

You can visit all the valid timezones here.

Reference

EDIT

Can you try using this to get the local date?

from django.utils.timezone import localtime, now

# get now datetime based upon django settings.py TZ_INFO
localtime(now())
crimsonpython24
  • 2,223
  • 2
  • 11
  • 27