3

I just querying Date field and assign value in date variable

//Date variable
public Date arrivalDate {get;set;}

now I am quering date field and assigning value in variable

arrivalDate = QueryField;

In the inputselect box, its showing

Mon Apr 18 00:00:00 GMT 2016

In the UI its showing GMT format in text field, how can I convert it into Date 'dd-mm-yyyy'

  • public Date arrivalDate {get;set;} //Initialise arrivalDate = System.today(); //Query List<Account> acc = [Select Id , CreatedDate From Account limit 1]; arrivalDate = acc[0].CreatedDate; //Arrival date is bind on VF page in input Text {!arrivalDate} – Yogesh Gupta Apr 18 '16 at 9:25
1

Reason: Salesforce store the dateTime value in database in GMT Format. When the dateTime display on standard page. It display in current user's time zone

Use in controller.. use strConvertedDate instead a.CreatedDate

DateTime format for current user

CreatedDate.format('MM/dd/yyyy,HH:mm', UserInfo.getTimeZone().getID()) or

CreatedDate.format('MM/dd/yyyy,HH:mm', UserInfo.getTimeZone().toString())

String strConvertedDate = a.CreatedDate.format('MM/dd/yyyy HH:mm:ss', UserInfo.getTimeZone().toString());

Use this string 'strConvertedDate' in VF

  • If use String type variable, then I will not able to show standard salesforce calendar on VF page, am I right ? – Yogesh Gupta Apr 18 '16 at 7:37
  • @YogeshGupta yes you can able to show the calender.. give a try I am not completely sure – Ratan Paul Apr 18 '16 at 7:39
  • while I am saving it giving an error Save error: Method does not exist or incorrect signature: [Date].format(String, String) – Yogesh Gupta Apr 18 '16 at 8:44
  • @YogeshGupta can you add your code snippet in your question, what you have tried so far? – Ratan Paul Apr 18 '16 at 8:56
  • public Date arrivalDate {get;set;} //Initialise arrivalDate = System.today(); //Query List<Account> acc = [Select Id , CreatedDate From Account limit 1]; arrivalDate = acc[0].CreatedDate; //Arrival date is bind on VF page in input Text {!arrivalDate} – Yogesh Gupta Apr 18 '16 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.