function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

date format

I have a date field in a custom object that I am going to populate from a visualforce page.


My method is as follows:


public date getStartDate() { date dtCurrentDate =; Integer i; date dtStartDate; i = dtCurrentDate.year(); string s = string.valueof('1/01/' + i); dtStartDate = date.parse(s); return dtStartDate; }


This displays my date on my visualforce page as:


1/01/09 12:00AM


How can I format to a shortdate as: 1/1/2009.  There is additional manipulation I will do to the date before inserting into the date field in my custom object, but I want to get the formatting to a shortdate without the time.


What I've been doing is convert the Date object to a DateTime ( use DateTime.newInstance(dateObj.year(), dateObj.month(), ) and then call format(String) on it. The params for this method is exactly same as that used in Java's SimpleDateFormat:


Thanks, I finally got this working correctly:


date dtDateFormat = date.valueof(workweek); tr.Work_Week__c = dtDateFormat; insert tr;


Message Edited by Dman100 on 12-23-2009 08:39 AM