Returns a Date that contains the value of the specified
String.The String should use the standard date format
"yyyy-MM-dd HH:mm:ss" in the local time zone. For
example:
stringyear='2008';
stringmonth='10';
stringday='5';
stringhour='12';
stringminute='20';
stringsecond='20';
stringstringDate=year+'-'+month
+'-'+day+''+hour+':'+
minute+':'+second;
DatemyDate=date.valueOf(stringDate);
Create a class that will manipulate the date so you can return any number of formats.
global class DateFormater{
private Date theDate;
private static List<String> monthList = new List<String>({'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'});
public DateFormater(Date theDate){
this.theDate = theDate;
}
public String customDate(){
String y = String.valueOf(this.theDate.year());
Integer m = this.theDate.month();
String d = String.valueOf(this.theDate.day());
return y.substring(2) + ' ' + DateFormater.monthList[m - 1] + ' ' + d;
}
}
You would call your new class like this.
DateFormater df = new DateFormater(date);
String myString = df.customDate();
Please note I have not compiled this code and have no idea if it will work, but it will get you started.
You can keep adding to your DateFormater class to support different formats that you want to have.
Try using a 4 digit year, and 2 digit month.
Jan = 01.
Returns a Date that contains the value of the specified String.The String should use the standard date format "yyyy-MM-dd HH:mm:ss" in the local time zone. For example: stringyear='2008'; stringmonth='10'; stringday='5'; stringhour='12'; stringminute='20'; stringsecond='20'; stringstringDate=year+'-'+month +'-'+day+''+hour+':'+ minute+':'+second; DatemyDate=date.valueOf(stringDate);
Apex doesn't support any date format other then what is in the docs.
You will need to write your own class that parses out the date and can return the format you want.
Can u pl's explain me how to do that.
Ex: 09 Jan 17
Create a class that will manipulate the date so you can return any number of formats.
global class DateFormater{ private Date theDate; private static List<String> monthList = new List<String>({'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'}); public DateFormater(Date theDate){ this.theDate = theDate;
} public String customDate(){ String y = String.valueOf(this.theDate.year()); Integer m = this.theDate.month(); String d = String.valueOf(this.theDate.day()); return y.substring(2) + ' ' + DateFormater.monthList[m - 1] + ' ' + d; } }
You would call your new class like this.
DateFormater df = new DateFormater(date); String myString = df.customDate();
Please note I have not compiled this code and have no idea if it will work, but it will get you started.
You can keep adding to your DateFormater class to support different formats that you want to have.
why are you making webservices?
I am not sure I follow the scope of your project?
What is the use case you are trying to solve here?