the Gravity of Python 2
Kushal Kumaran
kushal.kumaran at gmail.com
Thu Jan 9 01:06:29 EST 2014
Roy Smith <roy at panix.com> writes:
> In article <mailman.5231.1389240235.18130.python-list at python.org>,
> Chris Angelico <rosuav at gmail.com> wrote:
>
>> On Thu, Jan 9, 2014 at 2:35 PM, Roy Smith <roy at panix.com> wrote:
>> >> Yes, it *is* simple. It *is* easy. I've been working with pure-UTC
>> >> times (either called time_t, or TIMESTAMP WITH TIME ZONE, or even just
>> >> float) for decades. Like with so many other things, the easiest
>> >> solution is also the best, because you can just work with one stable
>> >> representation and abstraction on the inside, with conversions to/from
>> >> it at the boundaries. It IS that easy.
>> >
>> > Please show me the simple code to obtain an aware UTC datetime
>> > representing the current time.
>>
>> In Pike:
>> time();
>>
>> In PostgreSQL:
>> SELECT now();
>>
>> In C:
>> time(0);
>>
>> All of these give a value in UTC.
>
> None of which answer my question. How, in Python, do you get an aware
> UTC datetime object? I know how to get a numeric representation of the
> time as the number of seconds since the Unix epoch. That's not what I
> asked.
>
My local copy of the python 3.2.3 docs says:
classmethod datetime.utcnow()
Return the current UTC date and time, with tzinfo None. This is like
now(), but returns the current UTC date and time, as a naive
datetime object. An aware current UTC datetime can be obtained by
calling datetime.now(timezone.utc). See also now().
Hope this helps.
>> So maybe the key is to use utcfromtimestamp()? I don't know.
>
> So, I'm really confused what point you're trying to make. You started
> out arguing that I should be using aware datetimes instead of naive
> datetimes. I said that the reason I don't use aware datetimes is
> because they're so much more difficult to generate. You said they were
> simple to generate.
>
> So, I'd like to see your code which generates an aware UTC datetime
> object in Python. And then we can argue about whether it's simple or
> not :-)
--
regards,
kushal
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20140109/96758276/attachment.sig>
More information about the Python-list
mailing list