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'

1
  • 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} Commented Apr 18, 2016 at 9:25

1 Answer 1

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

6
  • If use String type variable, then I will not able to show standard salesforce calendar on VF page, am I right ? Commented Apr 18, 2016 at 7:37
  • @YogeshGupta yes you can able to show the calender.. give a try I am not completely sure
    – Ratan Paul
    Commented Apr 18, 2016 at 7:39
  • while I am saving it giving an error Save error: Method does not exist or incorrect signature: [Date].format(String, String) Commented Apr 18, 2016 at 8:44
  • @YogeshGupta can you add your code snippet in your question, what you have tried so far?
    – Ratan Paul
    Commented Apr 18, 2016 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} Commented Apr 18, 2016 at 9:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .