উত্তর:
ফর্ম্যাটিংটি এইভাবে করা যেতে পারে (আমি ধরে নিয়েছি যে আপনি এইচ এইচ: এসএসের পরিবর্তে এইচএইচ: এমএম বোঝাতে চেয়েছিলেন তবে এটি পরিবর্তন করা সহজ):
Time.now.strftime("%d/%m/%Y %H:%M")
#=> "14/09/2011 14:09"
স্থানান্তরিত করার জন্য আপডেট হয়েছে:
d = DateTime.now
d.strftime("%d/%m/%Y %H:%M")
#=> "11/06/2017 18:11"
d.next_month.strftime("%d/%m/%Y %H:%M")
#=> "11/07/2017 18:11"
require 'date'এই বিটিডব্লিউ জন্য আপনার প্রয়োজন ।
Dateজিনিস পাওয়ার সর্বোত্তম উপায় । যাইহোক, আমি অবশেষে বর্তমান রুবি সংস্করণগুলির জন্য এই উত্তরটি আপডেট করার সুযোগ হিসাবে আপনার মন্তব্যটি নিয়েছি।
require 'date'
current_time = DateTime.now
current_time.strftime "%d/%m/%Y %H:%M"
# => "14/09/2011 17:02"
current_time.next_month.strftime "%d/%m/%Y %H:%M"
# => "14/10/2011 17:02"
তারিখ জন্য:
#!/usr/bin/ruby -w
date = Time.new
#set 'date' equal to the current date/time.
date = date.day.to_s + "/" + date.month.to_s + "/" + date.year.to_s
#Without this it will output 2015-01-10 11:33:05 +0000; this formats it to display DD/MM/YYYY
puts date
#output the date
উপরেরটি উদাহরণস্বরূপ প্রদর্শিত হবে, উপরেরগুলি 10/01/15 প্রদর্শিত হবে
এবং সময়ের জন্য
time = Time.new
#set 'time' equal to the current time.
time = time.hour.to_s + ":" + time.min.to_s
#Without this it will output 2015-01-10 11:33:05 +0000; this formats it to display hour and minute
puts time
#output the time
উপরেরগুলি উদাহরণস্বরূপ, 11:33 প্রদর্শন করবে
তারপরে এটি একসাথে রাখার জন্য, শেষে যুক্ত করুন:
puts date + " " + time