Time conversion between ruby on rails and javascript vice versa?

前端 未结 5 1145
遇见更好的自我
遇见更好的自我 2020-12-23 14:06

How to convert ruby time to javascript time and vice versa?

Ruby on rails :

 Time.now

Javascript :

 new Date()
         


        
5条回答
  •  一向
    一向 (楼主)
    2020-12-23 14:46

    Use strftime to get miliseconds:

    
    

    And parse back to Ruby using to_date:

    params[:date].to_date
    

    to_date accepts few formats:

    '3-2-2001'
    '03/02/2001'
    '2001-02-03'
    '3rd Feb 2001'
    '20010203'
    

提交回复
热议问题