datetime - Rails not Date.strptime not getting accurate op -


07/28/2017 11:56 pm date , below current code:

date.strptime("07/28/2017 11:56 pm", '%m/%d/%y %h:%m %p').to_time

i'm getting o/p => 2017-07-28 00:00:00 +0530 want hours.what should ?

the problem you're converting date object doesn't have time component , converting time object. instead, can use either

time.strptime("07/28/2017 11:56 pm", '%m/%d/%y %h:%m %p') # => 2017-07-28 23:56:00 -0700 

or

datetime.strptime("07/28/2017 11:56 pm", '%m/%d/%y %h:%m %p') # => fri, 28 jul 2017 23:56:00 +0000 

and call call to_time on datetime if you'd like

datetime.strptime("07/28/2017 11:56 pm", '%m/%d/%y %h:%m %p').to_time # => 2017-07-28 23:56:00 +0000 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -