Help with ( US date to EU date ) | Sololearn: Learn to code for FREE!

+2

Help with ( US date to EU date )

import java.util.*; public class Program { public static void main(String[] args) { Scanner s=new Scanner(System.in); String usdate=s.nextLine(); if(usdate.contains("/")){ String arr[]=usdate.split("/"); String month=arr[0],date=arr[1], year=arr[2]; System.out.println(date+"/"+month+"/"+year); } else if(usdate.contains(" ")){ usdate=usdate.replaceAll(" ","/").replaceAll (",","/"); usdate=usdate.replaceAll("January","1").replaceAll("February","2").replaceAll("March","3").replaceAll("April","4").replaceAll("May","5").replaceAll("June","6").replaceAll("July","7").replaceAll("August","8").replaceAll("September","9").replaceAll("October","10").replaceAll("November","11").replaceAll("December","12"); String arr[]=usdate.split("/"); String month=arr[0],date=arr[1], year=arr[2]; System.out.println(date+"/"+month+"/"+year); } }}

4/16/2020 9:18:21 AM

Ajay

3 Answers

New Answer

+3

Ajay it works for me Have a look at this code: https://code.sololearn.com/cH2DQz6H1IfN/?ref=app

+3

Replace the 1st condition of else if with this statement and check whether it gives an error or not. usdate=usdate.replaceAll(", ","/").replaceAll (" ","/");

+1

No, it gives only 1/1 ie. Date/month as output