开发者

how to extract short date from a full date date string?

i am getting date from webs开发者_运维问答ervice

example: Wed, 29 june 2011 07:13:33

now i dont want to show full date with time zone just Wed, 29 june 2011 any one guide me how to achieve this?

any help would be appreciated.


try{
      SimpleDateFormat format1 = new SimpleDateFormat("E ,dd MMM yy hh:mm:ss");   
      SimpleDateFormat format2 = new SimpleDateFormat("E dd-MM-yyyy");    
      Date date = format1.parse(dateStr);     
      System.out.println(format2.format(date));  
 }
 catch(exception e){}


This problem was already solved on StackOverflow here: Java string to date conversion (that is converting date string to java date)

Here is for your example:

String inDate="Wed, 29 june 2011 07:13:33";
    Date date;
    try {
        date = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss", Locale.ENGLISH).parse(inDate);
        System.out.println(date); //Wed Jun 29 07:13:33 CEST 2011
    } catch (ParseException e) {
        e.printStackTrace();
    }

Printing out date itself should be the least of your problems

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜