Time#usecをstrftimeで使いたい

strftimeでusecが使いたいときがある.

  class Time
    alias replace_strftime strftime
    def strftime(fmt=nil)
      if fmt
        self.replace_strftime(fmt).gsub(/%#U/, self.usec.to_s)
      else
        self.to_s
      end
    end
  end
  
  t = Time::now
  puts t.strftime("%Y-%m-%d %H:%M:%S.%#U")