How to set timezone for my application deployed on RUN#Cloud - cloudbees
I am using the cloud bees to run our application. But the Time is being shown in GMT. What we want is IST ?
Here is the sample code :
Calendar cal = Calendar.getInstance();
TimeZone istTime = TimeZone.getTimeZone("IST");
cal.setTimeZone(istTime);
Date chkOut = cal.getTime();
startTripMapperObj.setRentalStartTime(chkOut);
Date chkOut2 = startTripMapperObj.getRentalStartTime();
RentalTrip r = new RentalTrip();
This is the output :
Trip Check In Wed Aug 15 14:34:20 GMT 2012
Trip Check Out Wed Aug 15 14:12:00 GMT 2012
by default the timezone is GMT - for java apps you can set the timezone yourself (I have seen some people do it in a servlet context listener so it runs on app startup time).
If you are using the cloudbees SDK, you can also set jvmTimeZone=XXX parameter which will then set it for all instance of that application from then on.
Related
How to determine and show the expiry time of a specific session
I am using spring-session and wondering how to know a specific session expired. Querying Redis persistence, I find a couple of the following lines [ root#redis-master-6fbbc44567-cc28m:/data ]$ redis-cli 127.0.0.1:6379> keys * 1) "spring:session:expirations:1581796140000" 2) "spring:session:sessions:23d6aff1-cb43-44f6-920d-cc3536ab6d46" 127.0.0.1:6379> Converting the expirations to date, they are equavalent to Mon 14 Feb 52095 16:40:00 GMT which looks weird at the year. We might extract the expired time from HttpSession: HttpSession httpSession = request.getSession() long currTime = System.currentTimeMillis() long expiryTime = currTime + httpSession.getMaxInactiveInterval() But the snippet doesn't show exactly what weed anticipate. I reckon we need to retrieve expirations from Redis server instead. What am I doing wrong here? Any of you know how to retrieve sessions and expirations from Redis?
The expiration timestamp 1581796140000 is a Unix epoch in milliseconds and translates to GMT: Saturday, February 15, 2020 7:49:00 PM.
How to set time zone to frecnh zone + windows ce
I need to set my timezone in my mobile device to french zone in c# (windows embedded ce) how can I do this please?
You can use this library to ease your development: https://opennetcf.codeplex.com/ I'm using it and setting the time zone through the following objects: TimeZoneCollection, TimeZoneInformation, DateTimeHelper.
You can not set the TimeZone to a city/location, you can only set the DST data. See my post here: http://community.intermec.com/t5/Device-Management/change-Time-Zone-with-xml/m-p/17007/highlight/true#M1023 ============================================================ You can not set the name of a TimeZone using the registry! You only can set the Offset and DST values. The clock panel then uses a matching entry. In the registry, the values for "GMT-7 (Mountain US)" and "GMT-7 (Arizona)" are nearly the same [HKEY_LOCAL_MACHINE\Software\Microsoft\Clock] "AppInfo"=hex(3):01,00,00,00,80,01,00,00,0f,00,00,00,00,00,00,00,00,00,00,00,3a,01,00,00,69,00,00,00,00,00,00,00,01,00,00,00 "AppState"=hex(3):11 "AutoDST"=dword:00000000 "GMT_OFFSET"=dword:000001A4 "HomeDST"=dword:00000000 "NetworkTimeNotifyUser"=dword:00000001 "NetworkTimeSync"=dword:00000001 "TZIndex"=dword:00000004 (see also http://peterfoot.net/HomeAndVisitingClocksInProfessionalEdition.aspx) and [HKEY_LOCAL_MACHINE\Software\Microsoft\Clock] "AppInfo"=hex(3):01,00,00,00,80,01,00,00,0a,00,00,00,00,00,00,00,01,00,00,00,3a,01,00,00,69,00,00,00,00,00,00,00,01,00,00,00 "AppState"=hex(3):11 "AutoDST"=dword:00000000 "GMT_OFFSET"=dword:000001A4 "HomeDST"=dword:00000001 "NetworkTimeNotifyUser"=dword:00000001 "NetworkTimeSync"=dword:00000001 "TZIndex"=dword:00000004 But, as you can see, there is no Name String of the time zone. [HKEY_LOCAL_MACHINE\Time] "TimeZoneInformation"=hex(3):a4,01,00,00,55,00,53,00,20,00,4d,00,6f,00,75,00,6e,00,74,00,61,00,69,00,6e,00,20,00,53,00,74,00,61,00,6e,00,64,00,61,00,72,00,64,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,55,00,53,00,20,00,4d,00,6f,00,75,00,6e,00,74,00,61,00,69,00,6e,00,20,00,44,00,61,00,79,00,6c,00,69,00,67,00,68,00,74,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,c4,ff,ff,ff and [HKEY_LOCAL_MACHINE\Time] "TimeZoneInformation"=hex(3):a4,01,00,00,4d,00,6f,00,75,00,6e,00,74,00,61,00,69,00,6e,00,20,00,53,00,74,00,61,00,6e,00,64,00,61,00,72,00,64,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0b,00,00,00,01,00,02,00,00,00,00,00,00,00,00,00,00,00,4d,00,6f,00,75,00,6e,00,74,00,61,00,69,00,6e,00,20,00,44,00,61,00,79,00,6c,00,69,00,67,00,68,00,74,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,03,00,00,00,02,00,02,00,00,00,00,00,00,00,c4,ff,ff,ff These are the TimeZoneInformations (the TIME_ZONE_INFORMATION structure). Clipboard02.gif You may query the timezone city db as done in the attached file (TZ-cities.txt). The attached tool (timezoneset.exe) can be used to change the offset of the current active timezone. The time zone informations for Prague and Berlin are the same: index: 95 short name: GMT+1 Prague,Budapest name: Central Europe Standard Time GMT offset: -60 dst name: Central Europe Daylight Time DST offset: 0 ... index: 110 short name: GMT+1 Berlin,Rome name: W. Europe Standard Time GMT offset: -60 dst name: W. Europe Daylight Time DST offset: 0 except for the dst name. It is no good idea to set timezone informations using the registry.
Linking datetimes of events to their associated location timezone (TimeZone gem, ActiveSupport::TimeWithZone)
I beat my head against this for a day and a half before it finally all came together, partly because I was fundamentally misunderstanding some things because of my assumptions of how things should work, and so the results I was getting seemed so completely irrational and confusing that I was starting to think things must be horribly broken in the libraries. They weren't. This thread is to share my question, and what worked, partly because it seems to me that a lot of times a datetime record should be tied to the localtime of its location, and a lot of times when applications behave strangely with respect to timezone changes I think it's because they don't do that. So here's how to do that. The easy part was using the TimeZone gem to get the location's timezone (I already have the latitude/longitude from using the GMaps4Rails gem), as described here: Ruby gem for finding timezone of location Initially, I hoped each datetime could have an intrinsic and persistent time zone, even after being saved and retrieved from the DB, since we only care about the local time zone for each event. For the unusual and rare case where the datetime was needed in other-than-local-zone, I could convert. But I guess that doesn't exist since MySQL seem to have no concept of timezone with its datetime, and just stores everything as a plain ol' date and time. So, that's fine -- the DB stores in UTC and I must do the conversions each direction. How? (See below.)
User enters a datetime (year, month, day, hour, min, sec) in the appropriate local time for the event location. To save this as the correct UTC time in your DB, and retrieve later retrieve it and use it with its correct timezone, here's the recipe: You must first set Time.zone = timezone -- where timezone is a named timezone string, like "America/Toronto" (GeoKit/TimeZone style) or "Eastern Time (US & Canada)" (Rails 3 style): 1.9.3p200 :001 > Time.zone = "America/Toronto" => "America/Toronto" Note that it is nontrivial to map between the GeoKit/TimeZone style and the Rails 3 style. There is some support for that, but many of the mappings that GeoKit returns are not in the Rails mappings, so I'm sticking with the GeoKit/TimeZone names because they seem to work just fine, and I don't need user-selectable timezones because I'm taking care of all of that automagically for the user using the locations. Now you can parse and save your datetime variable using ActiveSupport::TimeWithZone, and it will be encoded properly using the Time.zone parameter: 1.9.3p200 :002 > t = Time.zone.local( 2012, 8, 1, 12, 0, 0 ) => Wed, 01 Aug 2012 12:00:00 EDT -04:00 i.e. In my case, for my Event model with instance event: event.start = Time.zone.local( year, month, day, hour, min, sec ) event.save When the data is saved to the DB, it is in UTC: 2012-08-01 16:00:00.000000 (Simulated below with call to t.utc) 1.9.3p200 :003 > t = t.utc => 2012-08-01 16:00:00 UTC 1.9.3p200 :004 > t.zone => "UTC" Now, when you read it back from the DB, you need to again use the TimeWithZone support to tell the DateTime what timezone it is in. Note that the in_time_zone function does not change the underlying datetime variable's timezone: 1.9.3p200 :005 > t.in_time_zone( "America/Toronto" ) => Wed, 01 Aug 2012 12:00:00 EDT -04:00 1.9.3p200 :006 > t => 2012-08-01 16:00:00 UTC 1.9.3p200 :007 > t.zone => "UTC" so you really need to assign the function output back to your datetime variable: 1.9.3p200 :008 > t = t.in_time_zone( "America/Toronto" ) => Wed, 01 Aug 2012 12:00:00 EDT -04:00 1.9.3p200 :009 > t => Wed, 01 Aug 2012 12:00:00 EDT -04:00 1.9.3p200 :010 > t.zone => "EDT" Finally, a warning -- do not use t.time! It's output is completely useless and irrational, with the time and it's timezone out of sync: 1.9.3p200 :011 > t.time => 2012-08-01 12:00:00 UTC
changed? method always returns TRUE with DateTime field even is wasn`t changed (using jQuery UI datetimepicker)
I have encountered strange problem - when using jQuery UI datetimepicker (http://trentrichardson.com/examples/timepicker/) for editing DateTime field it seems like Rails thinks that this field is always changed even if I don`t changed it. The thing is that I have validation if this field changed and it is always executed. self.begin_time - self.changed_attributes["begin_time"] == 0.0 # => true self.begin_time_changed? #=> true I use text_field for displaying DateTime field and I specified Time format and initializer like this: Time::DATE_FORMATS[:default] = "%d.%m.%Y %H:%M" And even more: #d.begin_time # => Thu, 24 Nov 2011 14:00:00 MSK +04:00 #d.begin_time = "24.11.2011 14:00" #d.begin_time_change # => [Thu, 24 Nov 2011 14:00:00 MSK +04:00, Thu, 24 Nov 2011 14:00:00 MSK +04:00] #d.begin_time_changed? => true So times are equal and I don`t know how to make changed? method work properly.
Facing a problem with GWT Data Serialization
This is similar to the question: GWT Data Serialization I am using Date Object # my client, Here is what I tried, I created a Date Object, showed its toString() in a Label and passed it to server via Rpc whose return value is the same Date's toString() value passed: Date value = new Date(2011, 0, 19); Output # Hosted/Development mode : (http://127.0.0.1:8888/MyApplication.html?gwt.codesvr=127.0.0.1:9997) Client Reads: Thu Jan 19 00:00:00 IST 3911 Server reads:Thu Jan 19 00:00:00 IST 3911 Output # Production mode (after GWT compile) : (http://127.0.0.1:8888/MyApplication.html) Client Reads: Thu Jan 19 00:00:00 GMT+530 3911 Server reads:Thu Jan 19 00:00:00 IST 3911 Output # Deploying in Jboss running in the same Machine : Client Reads: Thu Jan 19 00:00:00 GMT+530 3911 Server reads:Wed Jan 18 18:30:00 GMT 3911 What's mind boggling is that its the same machine and hence the locale, etc should ideally be the same, still # hosted mode I see client sends IST server receiving IST, #production I see client sends GMT server receives IST and #Jboss server deploy I see client sends GMT and server receives GMT with one Day less !! The fact that the server recieves one day less is very seriously affecting my application business logic, basically I am using iBatis thats populating my pojos from database and sending it to client and at client I am using GXT which is showing me a UI for date selection. Using String for date is not suitable for me since its a major change in application core pojos, all database select and insert queries just because my client library does not handle Dates well. Does anyone have a alternative to this ?
You can try to use DateTimeFormat to build something that is unambiguous among machines despite locales. Format like 'yyyy-MM-dd HH:mm:ss ZZZZ' instead of using toString() Date today = new Date(); DateTimeFormat fmt = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss ZZZZ"); GWT.log(fmt.format(today));