Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Cameron Simpson
On 16Oct2020 22:07, Albert-Jan Roskam  wrote:
>   I was using datetime.now().isoformat('T', 'seconds')
>   Not 100% sure, but the strings seemed to be 2hrs off. Could it be that
>   this Linux server was using the wrong time zone?

Maybe. This is why timezones are such a nightmare, and programmes 
working with datetime as their primary structure are fragile (hmm, is 
this _naive_ (untimezoned) datetime in local time? What _is_ local time? Was 
the naive datetime obtained correctly?  etc).

Hence the common recommendation to work in seconds since an epoch (on 
UNIX that epoch is midnight 01 January 1970 GMT). Then timezones are 
just when presenting to a human.

But also, on UNIX and UNIX-like (Linux) the timezone is an aspect of 
your environment; setting the $TZ environment various suitably will 
display times according to your preference.  The system default for when 
$TZ is not set is usually in the /etc/timezone file, but you can set $TZ 
for yourself and have your own localtimes generally displayed.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread sjeik_appie
   On 16 Oct 2020 12:50, Eryk Sun  wrote:

 On 10/16/20, Steve  wrote:
 > -Original Message-
 > From: Python-list 
 On
 > Behalf Of Frank Millman
 > Sent: Friday, October 16, 2020 4:34 AM
 > To: python-list@python.org
 > Subject: Re: How do I get datetime to stop showing seconds?
 >
 > On 2020-10-16 9:42 AM, Steve wrote:
 >> d2 =  datetime.datetime.now() #Time Right now
 >> 

   I was using datetime.now().isoformat('T', 'seconds')
   Not 100% sure, but the strings seemed to be 2hrs off. Could it be that
   this Linux server was using the wrong time zone?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Cousin Stanley
Steve wrote:

> d2 =  datetime.datetime.now() #Time Right now
> 
> Show this: 2020-10-16 02:53
> and not this: 2020-10-16 02:53:48.585865
> 
> 
> ==
> Footnote:
> If you double major in psychology and reverse psychology, to they cancel
> each other out?
> 
> --

py> 
py> import datetime as dt
py> 
py> d = dt.datetime.now().strftime( '%Y-%m-%d  %H:%M' )
py> 
py> print( '\n  ' , d )

   2020-10-16  07:22


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Eryk Sun
On 10/16/20, Steve  wrote:
> -Original Message-
> From: Python-list  On
> Behalf Of Frank Millman
> Sent: Friday, October 16, 2020 4:34 AM
> To: python-list@python.org
> Subject: Re: How do I get datetime to stop showing seconds?
>
> On 2020-10-16 9:42 AM, Steve wrote:
>> d2 =  datetime.datetime.now() #Time Right now
>>
>> Show this: 2020-10-16 02:53
>> and not this: 2020-10-16 02:53:48.585865
>
>  >>>
>  >>> str(d2)
> '2020-10-16 10:29:38.423371'
>  >>>
>  >>> d2.strftime('%Y-%m-%d %H:%M')
> '2020-10-16 10:29'

datetime also supports the __format__ protocol [1]. For example:

>>> d2 = datetime(2020, 10, 16, 10, 29, 38, 423371)

>>> format(d2, '%Y-%m-%d %H:%M')
'2020-10-16 10:29'

>>> f'{d2:%Y-%m-%d %H:%M}'
'2020-10-16 10:29'

[1] https://docs.python.org/3/library/datetime.html#datetime.datetime.__format__
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: How do I get datetime to stop showing seconds?

2020-10-16 Thread Steve
Right on target, 
Many Thanks


FootNote:
If money does not grow on trees, then why do banks have branches?

-Original Message-
From: Python-list  On
Behalf Of Frank Millman
Sent: Friday, October 16, 2020 4:34 AM
To: python-list@python.org
Subject: Re: How do I get datetime to stop showing seconds?

On 2020-10-16 9:42 AM, Steve wrote:
> d2 =  datetime.datetime.now() #Time Right now
> 
> Show this: 2020-10-16 02:53
> and not this: 2020-10-16 02:53:48.585865
> 

 >>>
 >>> str(d2)
'2020-10-16 10:29:38.423371'
 >>>
 >>> d2.strftime('%Y-%m-%d %H:%M')
'2020-10-16 10:29'
 >>>


Frank Millman
-- 
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Marco Sulla
Another way is:

'{:%Y-%m-%d %H:%M}'.format(d2)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Frank Millman

On 2020-10-16 9:42 AM, Steve wrote:

d2 =  datetime.datetime.now() #Time Right now

Show this: 2020-10-16 02:53
and not this: 2020-10-16 02:53:48.585865



>>>
>>> str(d2)
'2020-10-16 10:29:38.423371'
>>>
>>> d2.strftime('%Y-%m-%d %H:%M')
'2020-10-16 10:29'
>>>


Frank Millman

--
https://mail.python.org/mailman/listinfo/python-list


How do I get datetime to stop showing seconds?

2020-10-16 Thread Steve
d2 =  datetime.datetime.now() #Time Right now

Show this: 2020-10-16 02:53
and not this: 2020-10-16 02:53:48.585865


==
Footnote:
If you double major in psychology and reverse psychology, to they cancel
each other out?

-- 

-- 
https://mail.python.org/mailman/listinfo/python-list