Q: how can i menction specific offset to be deducted while saving times or datetime in rails? I am having a datetime column to store employee check-in ,out times. my logic in the controller action to capture check-in is,
def check_in
 @employee = current_user.employee
 punch_record = @employee.in_outs.where("date = ?", Date.today).first
 punch_record.check_in = DateTime.now 
 punch_record.save
end

when a person clicks check-in then the above logic gets executed.And in database it saves the check-in by deducting the indian offset ,that is (05:30). and in view page, i am using the in_time_zone method to show the check_in time, back in indian timezone,so that its adding the offset(05:30). and the time is showing properly. this is working fine.
record.check_in.in_time_zone(record.time_zone).strftime(" %I:%M %P")

here the record time_zone = Mumbai
now i am facing the time_zone issue in import attendance, where a person fills the employee check-in,out times in spreadsheet and uploads it. the format that is used in excel sheet is 09:30 am.
so here i am using the following logic to convert it into datetime.
  irb(main):004:0> "09:30 am".to_datetime
  => Mon, 07 Nov 2016 09:30:00 +0000

here in this case the offset(05:30) is not getting deducted. how to make the offset deducted in this case?

A: You aren't comparing like with like.
In the first case you are doing:
record.check_in.in_time_zone(record.time_zone)

Which is taking the recorded datetime object (9:30 am) and converting it to the relevant time zone.
In the second case:
"09:30 am".to_datetime

Which is just setting date time to 9:30 am - you are doing nothing to convert it.
Replicate your logic in rails console by doing: 
"09:30 am".to_datetime.in_time_zone('Kolkata')

and you will find you get the right result.
If "9:30 am" is input that isn't UTC but represents the time in India itself, then to convert it to UTC simply do:
"9:30".in_time_zone('Kolkata').utc
 => 2016-11-07 04:00:00 UTC 

