You need to sign in to do that
Don't have an account?
Ken_Koellner
Create a Dateimte in a given User's timezone
A need to create a Datetime value in a given user's timezone. There are method for the current user and methods for GMT but no method for the current user.
Anyone know of a convenient way to do this. I can get there timezone from the user record. It will be a string like "America/New_York". I supposed a could build a table with all the offsets, look up the offset, then construct a datetime in GMT and add the appropriate number of hours.
Anyone know of a better way to do this?
-Ken
If you are trying to post to a vf page just output the field and it will render itself in the correct timezone.
Nope, That is creating date in user's local time zone.
I want to create date in any time zone. Code running in system mode, want to be able to pick a user and create 9:00AM in thier timezone.
I figure I could do it by taken all the time zone codes and putting it in a Custom Setting with offset. Then I could look up the offset, create a GMT date, and add the appropriate hours. That's kinda a pain. It would be nice if DateTime had a newInstance method that took a timezone name.
Hopefully this works for you...simply pass in the users timezone as you mentioned before.
Okay, now I would want to take "dt" and instanciate a datetime object and save it to a datetime field.
See, what I'm trying to do is create a datetime value for a user for whatever timezone they are in. I have a process that's going to take a string like "9:00AM" and I want to for a user in America/New_York create a datetime that's UTC-5 for 9:00 AM..
Look like you just have to convert it back to a datetime type.
building on the example:
or basically this is simple method you would call
It's basically all here... http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_datetime.htm .
Good luck!
That works great when you actually have a dateTime variable which is set to the appropriate time (your example of converting now). However, if you need to actually set the variable to a specific time, say October 25, 2011 6:00AM using 'Europe/London' then what would you use in you paramtime?