Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First off, I would want to store my data as UTC cause its a good starting point. </p> <p>So let me ask this, Why do you need the time in EST, is this for the end-user, or do you need to do logic on the server and need it in EST?</p> <p>If its for the enduser, an easy fix is to let the users browser handle converting to the correct time. On the server convert the datetime object to a timestamp:</p> <pre><code>timestamp = time.mktime(datetime_obj.timetuple()) * 1000 </code></pre> <p>And then on the web page instantiate a Date object:</p> <pre><code>var date_obj = new Date({{ timestamp }}); var datetime_string = date_obj.toString(); // the datetime_string will be in the users local timezone </code></pre> <p>Now, on the other hand, if you want to have the time in the correct zone on the server so you can perform logic on it. I recommend using the help of <a href="http://niemeyer.net/python-dateutil" rel="nofollow">python-dateutil</a>. It will allow you to easily swap to a different timezone:</p> <pre><code>from datetime import datetime from dateutil import zoneinfo from_zone = zoneinfo.gettz('UTC') to_zone = zoneinfo.gettz('America/New_York') utc = created # your datetime object from the db # Tell the datetime object that it's in UTC time zone since # datetime objects are 'naive' by default utc = utc.replace(tzinfo=from_zone) # Convert time zone eastern_time = utc.aztimezone(to_zone) </code></pre> <p>Now if you really wanna store the datetime in EST, you need change the time on the DB server (like Ajay Yadav and gorus said). I don't know why you want to store them as EST, but then again I don't know what your application is.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload