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
Dman100Dman100 

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 = date.today(); 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.

asadimasadim

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

 

http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

Dman100Dman100

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