You need to sign in to do that
Don't have an account?

How to convert list of DateTime
Hi Experts!
I'm trying to convert list of Account's created date to a specific timeZone. Like PST.
I'm able to convert a single record like below.
But how will I go about converting a list of Create Dates like.
I'd like to convert these dates then call them in my visualforce page apex table.
Thank you in advance!
-Zach
I'm trying to convert list of Account's created date to a specific timeZone. Like PST.
I'm able to convert a single record like below.
public class accountTimeZone { public account acc{get;set;} public String LocalDate{get;set;} public accountTimeZone(){ acc = [select createdDate from Account where id = '0019000001JCS1x']; LocalDate = acc.createdDate.format('MMMM dd, yyyy hh:mm a','America/New_York'); System.debug(LocalDate); } }
But how will I go about converting a list of Create Dates like.
public class accountTimeZone { public list<account> AccountDate {get;set;} public list<DateTime> convertedDate{get;set;} public accountTimeZone(){ AccountDate = [select createdDate from account limit 5]; } }
I'd like to convert these dates then call them in my visualforce page apex table.
Thank you in advance!
-Zach
We forgot to assign the memory for the list.
Just add one more line, it should work fine for you -
Let me know, if it helps you.
Thanks,
Sumit Kumar Singh
All Answers
You can try this -
Pls, let me know, if it helps you.
Thanks,
Sumit Kumar Singh
Hi Zach,
Salesforce DB saves DateTime field in GMT Format.
You can use Timezone class in salesforce to convert your dateTIme field according to your Timezone.
You can check out this link for more info:
http://salesforce.stackexchange.com/questions/8538/convert-time-from-a-different-timezone-other-than-local-to-gmt
Hope this helps.
Thanks for the Response, I've tried the code before I submitted this question but I was getting an Error.
Error: accountTimeZone Compile Error: Illegal assignment from String to Datetime at line 19 column 22
Since the value that we are passing to the dt variable is Text. However, when I change the variable and List to String like below..
I will get Error: System.NullPointerException: Attempt to de-reference a null object
Thank you.
-Zach
Thank you for the Suggestion. I will read about the TimeZone Class. :)
We forgot to assign the memory for the list.
Just add one more line, it should work fine for you -
Let me know, if it helps you.
Thanks,
Sumit Kumar Singh
Thanks Sumit! This worked! You did it again :)