# Updated\_at with client time not server time

**URL:** <https://www.ruby-forum.com/t/updated-at-with-client-time-not-server-time/140882>\
**Category:** Rails\
**Created:** [June 19, 2008, 2:12pm UTC](https://www.ruby-forum.com/t/updated-at-with-client-time-not-server-time/140882 "2008-06-19T14:12:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [June 19, 2008, 2:12pm UTC](https://www.ruby-forum.com/t/updated-at-with-client-time-not-server-time/140882/1 "2008-06-19T14:12:12Z")

</div>

Hi,

I use the t.timestamps that are automatically added by rails. So there  
is the created\_at and updated\_at columns in the DB.

When I create an entry those are filled with the server time when the  
request is created or updated.

I want that to be the client time, if I do the request from Europe now I  
get US time in the DB.

How to do it? Do I need to send explicitely time info from the client  
with JS for example or can I check from the request at server side? Any  
practical examples?

Thanks.

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [June 19, 2008, 2:23pm UTC](https://www.ruby-forum.com/t/updated-at-with-client-time-not-server-time/140882/2 "2008-06-19T14:23:28Z")

</div>

Have a look at timezone support in Rails 2.1. You’ll be able to keep  
the timestamps based on the time on the server (as they should be  
anyway), and you’ll be able to show data in the timezone of the  
client.

> **[\#106 Time Zones in Rails 2.1 - RailsCasts](http://railscasts.com/episodes/106-time-zones-in-rails-2-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Regards,  
Craig

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [June 19, 2008, 2:28pm UTC](https://www.ruby-forum.com/t/updated-at-with-client-time-not-server-time/140882/3 "2008-06-19T14:28:18Z")

</div>

Thanks Craig I’ll take a look. Of course I can convert those to client  
time, what was I thinking of 8-P

Cheers!

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [June 20, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/updated-at-with-client-time-not-server-time/140882/4 "2008-06-20T16:32:52Z")

</div>

Hmmm. My users do not select a time zone and I am not planning to ask  
them to provide it for some reasons. I should be able to provide the  
client time, I guess I’ll need to use some javascript to get the local  
time and store it at server side. That is mostly ok but clients running  
on mobile might be unable to us js…

Regards

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [June 20, 2008, 8:11pm UTC](https://www.ruby-forum.com/t/updated-at-with-client-time-not-server-time/140882/5 "2008-06-20T20:11:34Z")

</div>

comopasta Gr wrote:

> Hmmm. My users do not select a time zone and I am not planning to ask  
> them to provide it for some reasons. I should be able to provide the  
> client time, I guess I’ll need to use some javascript to get the local  
> time and store it at server side. That is mostly ok but clients running  
> on mobile might be unable to us js…

Jumping in late: Isn’t either your timezone, or a hint, available in  
standard  
HTTP headers??

Otherwise, asks DNS-land where their IP looks like it is. If they  
spoofed it,  
that’s on them…

Dilbert changes around midnight for me, for example. I have not checked  
this  
phenom from other time zones…

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [June 20, 2008, 9:37pm UTC](https://www.ruby-forum.com/t/updated-at-with-client-time-not-server-time/140882/6 "2008-06-20T21:37:10Z")

</div>

Hi,

Yeah I was checking the requests that the client sends. There are no  
hints about client’s time zone. In the reply from the server the date is  
shown but not in the request from the client.

I continued searching and there’s been similar questions in the forum:  
[http://www.ruby-forum.com/topic/112085#new](http://www.ruby-forum.com/topic/112085#new)

Javascript seems to be the only choice. Getting location based on IP  
would be good but will slow down the app and is not so accurate.

Regards
