কম্পিউটার টিউটোরিয়াল

পাইথনে datetime.now() থেক মিনিট, সেকেন্ড এবং মিলিসেকেন্ড কীভাবে পাবেন?

আপনি strftime ফাংশন ব্যবহার করে ফরম্যাট করা ডেট ও টাইম পেতে পারেন। এটি একটি ফরম্যাট স্ট্রিং এক্সেপ্ট করে যা আপনি আপনার ইচ্ছামত আউটপুট পেতে ব্যবহার করতে পারেন। নিচে সাপোর্টেড ডাইরেক্টিভগুলো দেওয়া হলো:

DirectiveMeaning
%aLocale's abbreviated weekday name.
%ALocale's full weekday name.
%bLocale's abbreviated month name.
%BLocale's full month name.
%cLocale's appropriate date and time representation.
%dDay of the month as a decimal number [01,31].
%HHour (24-hour clock) as a decimal number [00,23].
%IHour (12-hour clock) as a decimal number [01,12].
%jDay of the year as a decimal number [001,366].
%mMonth as a decimal number [01,12].
%MMinute as a decimal number [00,59].
%pLocale's equivalent of either AM or PM.
%SSecond as a decimal number [00,61].
%UWeek number of the year (Sunday as first day of week) as decimal [00,53].
%wWeekday as a decimal number [0(Sunday),6].
%WWeek number of the year (Monday as first day of week) as decimal [00,53].
%xLocale's appropriate date representation.
%XLocale's appropriate time representation.
%yYear without century as a decimal number [00,99].
%YYear with century as a decimal number.
%ZTime zone name (no characters if no time zone exists).
%%A literal "%" character.

উদাহরণ

এই কেসে, আপনি এই ডাইরেক্টিভগুলো strftime ফাংশনে নিচের মত ব্যবহার করতে পারেন:

from datetime import datetime
curr_time = datetime.now()
formatted_time = curr_time.strftime('%M:%S.%f')
print(formatted_time)

আউটপুট

এটি নিচের আউটপুট দেবে:

31:15.093393
  1. জাভাতে মিলিসেকেন্ড থেকে ডেট ও টাইম ফরম্যাট করার পদ্ধতি

  2. Python 3-এ Tkinter filedialog থেকে স্ট্রিং পাওয়ার পদ্ধতি

  3. Python-এ datetime অবজেক্ট থেকে শুধু মাস ও দিন বের করা

  4. Tkinter-এ চেকবক্স থেকে ইনপুট পাওয়া