• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

How to set a default timezone?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I'm making this android app in java and when a user clicks on a button it sends to a server a package with some informations, one of them is the moment(hh:mm:ss) of the click. I'm gonna use this information to add data into a database. The one who clicked first is added before the one who clicked after. The problem is the timezone. I was thinking about use a default timezone. The idea is no matter where do you use this app, when you click on that button it will be like everyone is in the same time zone. Here what I tried but is no working.
How can I do that?


Output:
 
Marshal
Posts: 26750
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you have the server assign the current server time to each transaction it receives? That has at least two benefits: first, it makes your problem go away, you don't even need to send the client's time to the server. But second, and more important, there is no guarantee that the Android client devices have anything near the correct time as the current time.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It basically design question, 1. what you want to store depends on your usage.
For example if I want to store the client time in DB and later want to show same time to client then I can store the same timestamp as string .
If you want to perform some functionality on client time in server side , client time and UTC time also can be stored.
I will recommend to store client time(time at which user pressed button) and server side convert it to UTC time and store both.
client time stored can be used for particular transaction and UTC time used for processing two different timezones.
 
Paul Clapham
Marshal
Posts: 26750
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And if you want the client time for that sort of reason, the way to make it independent of time zones is to call System.currentTimeMillis(). That method returns

The API documentation wrote:the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.



And just a suggestion, the old java.util.Date and Calendar classes are now obsolete. The newer classes in the java.time package are more flexible.
 
antonio caipora
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Why don't you have the server assign the current server time to each transaction it receives? That has at least two benefits: first, it makes your problem go away, you don't even need to send the client's time to the server. But second, and more important, there is no guarantee that the Android client devices have anything near the correct time as the current time.


Because I need the moment of the click. It does'nt matter if the client current time is not correct because the consequence of this is not very important.
 
antonio caipora
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

subhash kumar wrote:If you want to perform some functionality on client time in server side , client time and UTC time also can be stored.


Yes, I want to perform some functionality based on client button click time. But to be fair with everybody using the app I would like to set a default timezone. Acctually I was looking for some kind of "universal" metric like the old and dead
'Swatch Internet Time". Something like that would be perfect for what I need.
 
Paul Clapham
Marshal
Posts: 26750
81
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

antonio caipora wrote:It does'nt matter if the client current time is not correct because the consequence of this is not very important.



In some applications it's extremely important to put events on a distributed network into the correct time sequence, and there's a whole lot of very complicated math which tries to make that happen. So it's good that you don't have that problem.

As for the universal time zone, its name is UTC. So if you use System.currentTimeMillis() on the client systems and send that long value to the server, the server can then set up a date-and-time formatter which uses the UTC time zone to display that instant. Or perhaps the server itself could run under UTC.
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic