Mohamed Szollosi: Dude use variables. Less bugs and less problems.String date = "11/12/1300"; int begIndex = 0;int endIndex = date.indexOf("/");String months = date.substring(begIndex, endIndex); begIndex = endIndex + 1; endIndex = date.indexOf("/", begIndex);String days = date.substring(begIndex, endIndex);String years = date.substring(endIndex + 1);System.out.println(months + "-" + days + "-" + years);...Show more
Douglass Sarley: String[] tokens = date.split("/");for(String s: tokens)System.out.println(s);
Refugio Gastineau: If you want all the math capabilities of Date, use a Date. After all, when I want a Twinky, I go to Hostess. public static void main( String[] args ) { Calendar date = Calendar.getInstance(); // then set the turkey, note .set( int, int, int);// note months start with 0 = Jan ... Dec = 11 date.set( 1999,9,14); // get the lowest common denominator, milli// with milli you can calc past and future dates ! long millisecs = date.getTimeInMillis(); // now you can output the format you want Date d = new Date(millisecs); // format it the way u like it String s = DateFormat.getDateInstance().format(d); System.out.println(s); System.out.printf("Finals are on: %s%n", DateFormat.getDateInstance( DateFormat.LONG ).format( d ) ); }...Show more
No comments:
Post a Comment