E
E
Egorian2018-04-05 18:24:25
Python
Egorian, 2018-04-05 18:24:25

datetime. How to write time correctly?

from datetime import datetime
def date_time(time):
  dt=datetime.strptime(time, "%d.%m.%Y %H:%M")

  #lstrip()-убираю пробел в начале. К делу не относится
  # lstrip("0").replace(" 0"," ")-меняю 00 на 0                                                                                               
  return dt.strftime("%e %B %Y year %H hours %M minutes").lstrip().lstrip("0").replace(" 0"," ")

How to remove hours 's' from when it is 1? Minutes are the same. I am sure that this can be done without if and elif

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex F, 2018-04-06
@Egorian

Wrote a module .
Tried:

#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-
import locale
import myplur
from datetime import datetime

locale.setlocale(locale.LC_ALL, 'ru_RU.utf8')

now = datetime.now()
hour = now.hour
minut = now.minute
print(hour, myplur.PlurHour(), minut, myplur.PlurMin())

Exhaust: And yes, on "if...else".

D
Dimonchik, 2018-04-05
@dimonchik2013

strftime

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question