Search code examples
javadatetimestampdate-formatting

Convert a date string with time zone to only weekday and date


I'm having a string like this: Wed Feb 20 02:48:00 GMT+05:30 2019 and I need to convert it to Wed 20.

How can I do this?

I tried string.replace(), but that doesn't help I'm a newbie please help


Solution

  • try this

    class Test
    {
            public static void main(String ... args)
            {
                    String s="Wed Feb 20 02:48:00 GMT+05:30 2019";
                    String arr[]=s.split(" ");
                    if (arr.length >=3)
                    {
                            String result=arr[0]+" "+arr[2];
                            System.out.println(result);
                    }
            }
    }
    $ java Test
    Wed 20