How to connect in telegram bot on Python time? If, for example, I want a person to write "What time is it now?"

    1 answer 1

    I think it is worth using the datetime library, in which there is a function now .

    If you are going to write a bot using the pyTelegramBotAPI library, then the problem is solved as follows: in the message_handler for the query "What time is it?" you will need to use the bot.reply_to(message, "Время: " + str(datetime.now())) function bot.reply_to(message, "Время: " + str(datetime.now()))

    • this assumes that the server on which the bot is running uses Moscow time. Instead, you can obviously get the right time: DT.datetime.now(pytz.timezone('Europe/Moscow')) where the import datetime as DT and pip install pytz - jfs