Leading Zero for time


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-zfe3o/2/3?curriculum_id=5059f8619189a5000201fbcb

Lesson: Extend your Knowledge: Time, Here and Now

My question is about time, after the code below. But follow to see why I ask the question.

I happened to have coded this at 9:05 and noticed that it returned

=> It's 9:5 AM

Thankfully I was coding not 5 minutes sooner or later, I would have thought I understood time.

After a lot of searching, I found a few things I didn't understand how to implement. Eventually I found strftime and began to understand it. Hopefully codecademy will explain this further, but I decided to post this lest someone else go down the rabbit hole.
Info about strftime : http://ruby-doc.org/core-2.1.0/Time.html#method-i-strftime

module ThePresent
  def now
      t=Time.new
#      t=Time.new(2017,2,23,9,5,3,"-07:00")
l=t.getlocal
puts t.zone
puts l.zone
      puts l.strftime("Localtime is %A the %e %I:%M%p %Z")
    puts t.strftime("Zulu time is %A the %e %I:%M%p %Z")
 #   puts "It's #{t.hour > 12 ? t.hour - 12 : t.hour}:#{t.min} #{t.hour > 12 ? 'PM' : 'AM'} (GMT)."
  end
end

class TheHereAnd
  extend ThePresent
end

TheHereAnd.now

My question: Why does local time equate to the same as UTC? Not PST
How/Can Ruby obtain the user's local time?

Thanks,
Eric


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.