Sanat Pandey Sanat Pandey - 10 months ago 33
Android Question

Converting Timestamp value in a prticular Date Time Format

I have a problem that I have a timestamp value which is coming from JSON parsing, I am converting that timastamp in Date Time Format which is desired, all is working fine but month always return 1 in any case. means If timestamp contains aug month but it returns only 1 for any month. I don't know how to resolve this. Please suggest me the solution for the same.

Thanks in advance.


public String create_datestring(String timestring){
final Calendar cal = Calendar.getInstance();
timestring = String.valueOf(cal.get(Calendar.MONTH)+1) + "/" +String.valueOf(cal.get(Calendar.DAY_OF_MONTH)) + "/" + String.valueOf(cal.get(Calendar.YEAR));
}catch(NumberFormatException e){
timestring = "9/23/2011";--->timestring always returns 1 for month.

private String getDate(String timeStampStr){

        DateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        Date netDate = (new Date(Long.parseLong(timeStampStr)));
        return sdf.format(netDate);
    catch(Exception ex){
        return dateInStr;