You need to sign in to do that
Don't have an account?
RajanJasuja
Is there any way to get current date and time as per the logged in user time zone in apex?
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11">
Hi,
Is there any way to get current date and time as per the logged in user time zone in apex?
I used System.now(), but its returning as per GMT time zone.
I need it as per the user time zone.Like if logged in use time zone is Singapore time zone then it should return current time and date as per the Singapore time zone which is GMT+8, not as per the GMT time zone.
Thanks and Regards,
Rajan Jasuja
The first line in the getlongDate method initializes the ‘cDT’ variable with the current datetime. The second line uses the “format” instance method to set a global string variable “LongDate”, using the following SimpleDateFormat string: ‘EEEE, MMMM d, YYYY’ The four letters indicate that the Day, Month and Year should be spelled out in full (non-abbreviated) form.
With the Java Class SimpleDateFormat instance method, you can display the date in any format that you want. Read more about Java Class SimpleDateFormat on the Java website: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
The code (and the VF page output) is displayed below.
Message Edited by JPSeabury on 09-16-2008 06:59 AM
All Answers
Have you tried
Date obj = Date.today();
Thanks,
The first line in the getlongDate method initializes the ‘cDT’ variable with the current datetime. The second line uses the “format” instance method to set a global string variable “LongDate”, using the following SimpleDateFormat string: ‘EEEE, MMMM d, YYYY’ The four letters indicate that the Day, Month and Year should be spelled out in full (non-abbreviated) form.
With the Java Class SimpleDateFormat instance method, you can display the date in any format that you want. Read more about Java Class SimpleDateFormat on the Java website: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
The code (and the VF page output) is displayed below.
Message Edited by JPSeabury on 09-16-2008 06:59 AM
thanks JPSeabury, it worked !!
Hi All,
Please use the below code and it works:
To get the current Datetime in the local time zone, you can use the following code:
Datetime now = Datetime.now(); Integer offset = UserInfo.getTimezone().getOffset(now); Datetime local = now.addSeconds(offset/1000);
If it helps don't forget to mark this as a best answer!!!
Thanks,
Mohammad Anis