M
M
Michael S.2021-06-30 21:42:00
Python
Michael S., 2021-06-30 21:42:00

I am writing a telegram bot, but he does not want to convert the time?

I want to convert the message.date format to %H:%M:%S, but somehow it doesn't work. Please tell me here is a sample code

import datetime
import settings
from datetime import datetime as dt
from aiogram import Bot, Dispatcher, executor, types

bot = Bot(token = settings.TOKEN)
dp = Dispatcher(bot)

@dp.message_handler(commands = ['start'])
async def send_start_commands(message: types.Message):
  await message.answer('Ваше имя: ' + str(message.from_user.first_name) + '\nФамилия: ' + str(message.from_user.last_name)
  + '\nВаш ник: ' + str(message.from_user.username) + '\nИ, да, вы написали мне это сообщение ровно в + dt.fromtimestamp(message.date).strftime('%H:%M:%S')')

if __name__ == '__main__':
  executor.start_polling(dp, skip_updates = True)


Throws an error: TypeError: an integer is required (got type datetime.datetime)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-06-30
@BUUSSA

message.datealready an object of type datetime, so no further conversion is needed. Straightawaymessage.date.strftime('%H:%M:%S')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question