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

পাইথনে ফরম্যাট করা ডেট ও টাইম কীভাবে পাবেন?

আপনি 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].
%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 ফাংশনে নিচের মত ব্যবহার করতে পারেন -

উদাহরণ

import datetime
now = datetime.datetime.now()
print("Current date and time: ")
print(now.strftime('%Y-%m-%d %H:%M:%S'))
print(now.strftime('%H:%M:%S on %A, %B the %dth, %Y'))

আউটপুট

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

2017-12-29 12:19:13
12:19:13 on Friday, December the 29th, 2017
  1. জাভাস্ক্রিপ্টে বর্তমান তারিখ এবং সময় পাওয়ার পদ্ধতি

  2. জাভাস্ক্রিপ্টে বর্তমান তারিখ ও সময় পাওয়ার উপায়

  3. জাভাস্ক্রিপ্টে epoch থেকে সময় ও তারিখ বের করার উপায়

  4. iOS-এ ইন্টারনেট থেকে বর্তমান তারিখ ও সময় আনা