Monday, September 26, 2011

Changing the Format of date(Java)

//This Java program accepts the date from the user in American
//format and then converts it to the European format.
//Sample input : 11/27/2011
//Output : The edited Date is : 27.11.2011
import java.util.*;
class changingDateFormat
{
public static void main(String Args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the date in month/day/year format");
String date=sc.next();
String day="",month="",year="";
int l=date.length();
int i,k=0;
char c;
String new_Date="";
for(i=0;i<l;i++)
{
c=date.charAt(i);
if((c!='/')&&(k==0))
{
month=month+c;
}
else if((c!='/')&&(k==1))
{
day=day+c;
}
else if((c!='/')&&(k==2))
{
year=year+c;
}
else if(c=='/')
{
k++;
}
}
new_Date=day+"."+month+"."+year;
System.out.println("The edited Date is : "+new_Date);
}
}
//Author : Mayank Rajoria

No comments:

Post a Comment