Discussion
Tech Mahindra
US
Last activity: 1 Jun 2017 14:11 EDT
Displaying time in sync to the Time zone of the users
Hi ,
In a drop down we are displaying current Date time but we need to display the date time according to the user time zone.
Is there any particular method,function or inbuilt activity to display the time in according to the time zone.
Thnaks in advance
Regards
anusha
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Pegasystems Inc.
US
There is a DateTime Library Function named: pxGetSpecifiedTimeOnDate
Description: Returns a datetime stamp for a specified time on a given day. Uses requestor's default time zone if not specified, and current date if time not specified. Input can be either date or datetime.
Usage: For instance, let's say the SLA time needs to be set to 11:59 pm on the next business day. You can call @pxGetSpecifiedTimeOnDate(@nextBusinessDay(@getCurrentTimeStamp(), pxRequestor.pyCalendar), 23, 59, 0, "")
Say you want an exam to always start at 9am EST/America/New_York on whatever day it is scheduled regardless Daylight Savings Times (timezones take that into consideration).
Answer: @(Pega-RULES:DateTime).pxGetSpecifiedTimeOnDate(.ExamStartDate, 9, 0, 0, "America/New_York")
Note above that .ExamStateDate is a DateTime.
The description says you can use Date but that might cause the result to be off by 24 hours unless you know for certain that the Date in the targeted time zone would be the same as the Date for the source at the indicated hour of the day.
For example the date in Australia is one day greater than it is in Hawaii due to the International Date Line lying between those two locations.
Best to use DateTime since it is an absolute value.
-
Balaji Srinivasaraghavan
Pegasystems Inc.
US
In my answer above I assume you are creating a datetime in the user's timezone as opposed to displaying a previously created datetime in the user's timezone.
You mentioned a dropdown so assumed you meant the former - the scenario being a user choosing a date and time of day within their local timezone to schedule something, e.g., an SLA.
As far as where to obtain the user's timezone, that information is stored on the user's Operator record.
Does this answer your question?
Tech Mahindra
US
Hi pedel,
irrespective of servers time zone i need to display the time,date and time zone of the local system.
we tried using below java code.But it's displaying server time zone instead of Local system time zone.
t1 = java.util.TimeZone.getDefault().toString();
t2 = java.util.TimeZone.getDefault().getDisplayName().toString();
t3 = java.util.TimeZone.getDefault().getID().toString();
but it is taking the time zone mentioned in the operator id instead of taking it from the system settings
please suggest me the some resolution
regards
Anusha
Pegasystems Inc.
US
You said "system settings".
Where/how are you storing the timezone of the server?
Datetimes are absolute values expressed in GMT / UTC when written to the database,
Guessing you are trying to display information such as a case's pxCreateDateTime and/or pxUpdateDateTime. Why wouldn't you want this information information presented in the user's time zone?
What you want instead is to display all times in the server's time zone?
Is there only one official "server time zone", for example, the location of the corporate headquarters, or does the value have to change depending where the server is deployed?
Let's say the server's timezone is stored somewhere, e.g., in a node-level declare page or dynamic system setting.
There are two "toLOCAL" Functions in the Datetime Library where the second argument is a timezone.
Would either of these work?
Pega
IN
Hi Anusha,
Did you get a solution for this problem?
We have similar requirement.
Pegasystems Inc.
US
Appears I misinterpreted your issue. You said:
- irrespective of servers time zone i need to display the time,date and time zone of the local system.
- but it is taking the time zone mentioned in the operator id instead of taking it from the system settings
So:
- both the timezone of the "server" and "Operator record" is different from the "local system" -- local system being what?
- The timezone that you want to use for the user is defined in "system settings"
Is that true?
If you can get at the timezone to use in System Settings, you can then use it as the second parameter when calling DateTime toLOCAL().
You also said you are displaying times in a DropDown.
The server's GMT time could be the value for the DropDownn with pyLabel being that time expressed in the user's local time zone.
Pega
IN
Hi PEDEL,
we have requirement of user selecting the timezone, it would update the operatorid's pydefaulttimezone property and by using PRDate..format() we are able show time as per the timezone but we have a requirement in addition to timezone we need to show GMT/IST/PST etc. to the date time fileds.
How we can able to get the details like if we have America/New York it would be EST do we have any OOTB where we can get all these 3 digit time format to display
Pegasystems Inc.
US
You should also look at: DateTime • pxGetSpecifiedTimeOnDate which has a timezone argument and lets you name the time of day.
You first though have to get "close", meaning provide the right day.
Suppose a future date crosses over from Daylight Savings to Standard time?
The "D" in EDT stands for "Daylight" and there is also "EST" where the "S" means "Standard".
Daylight Saving is from Spring to Fall; Standard time is Fall to Spring.
Different locations in the same longitude band may or may not observe Daylight Savings.
Plus in some cases local time is offset by a half hour compared to GMT.
Do not know of any OOTB solution.
Pega
IN
Thanks for your respone.
Our requirement is just for display, user can dynamically change his timezone lets take from EST/EDT to PST, then the case information with datetime fields like object create date times should change from EST/EDT to PST.
Apple India Pvt Ltd
IN
Simple use @CurrentDate(yyyyMMdd, pxRequestor.pyDefaultTimeZone)).
Becton Dickinson
IN
Thanks a lot Bala for the solution. I tried it yesterday and it works perfect!
Pega
IN
Hi Bala,
We have datetime property which changes as per the timezone we passed, we need to show what timezone it is like EST/IST etc.
We have timezone drop down available to the user where he would change at runtime we need to show the time as per the select timezone which is working for us but only problem is that we need to show 3 letter after the date time value displayed at every reference of datetime properties in the case.
Pegasystems Inc.
US
Perhaps you need an additional Text property for every date that you display?
The text property would be populated by a Declare Expression that concatenates the datetime value the user should see to the 3-letter timezone that the user selected.
Apple India Pvt Ltd
IN
Tech Mahindra
US
Our Requirement is bit different i hope,need to show the local time zone.Suppose if user is operating form india in that drop down it should display Indian time.
We are using CurrentDateTime() method to get the DateTime for the action taken.
and then
we are loading some X section before loading the Drop Down section.
That X section is generated using JSP.Below is the JSP Code.
------------------------------------
<script type="text/javascript">
function getOffsetLocale(){
var currDate = new Date();
var userOffset = -currDate.getTimezoneOffset() / 60;
userOffset = "GMT" + userOffset;
if(userOffset.indexOf("-")<0){
userOffset = userOffset.replace("GMT","GMT+");
}
var oSafeURL = new SafeURL("CLASS.GetOffsetTimezone");
oSafeURL.put("tzOffset",userOffset);
var ret = httpRequestAsynch(oSafeURL.toURL(),null,50,100);
}
getOffsetLocale();
</script>
In the above script need to mention your own class.
and in the activity GetOffsetTimezone
Our Requirement is bit different i hope,need to show the local time zone.Suppose if user is operating form india in that drop down it should display Indian time.
We are using CurrentDateTime() method to get the DateTime for the action taken.
and then
we are loading some X section before loading the Drop Down section.
That X section is generated using JSP.Below is the JSP Code.
------------------------------------
<script type="text/javascript">
function getOffsetLocale(){
var currDate = new Date();
var userOffset = -currDate.getTimezoneOffset() / 60;
userOffset = "GMT" + userOffset;
if(userOffset.indexOf("-")<0){
userOffset = userOffset.replace("GMT","GMT+");
}
var oSafeURL = new SafeURL("CLASS.GetOffsetTimezone");
oSafeURL.put("tzOffset",userOffset);
var ret = httpRequestAsynch(oSafeURL.toURL(),null,50,100);
}
getOffsetLocale();
</script>
In the above script need to mention your own class.
and in the activity GetOffsetTimezone
need to Create a page
and then a Java Step
String timezoneoffset = tools.getParamValue("tzOffset");
offsetVal = timezoneoffset;
offsetNumber = offsetVal.substring(3);
where it will give you a Local.offsetNumber
which is the difference between the time GMT and IST for me(+5.5).
with this result i hope you can write a decision table like for "+5.5" difference as ISt and so on.