java - how to write date using tokenizer? -
the following code here returns date in form "day, date, month, year".
date entered in return saturday 28 dec 2013. however, want tokenize , print 4 parts out on 4 separate lines, starting month, date, year, day. what's best way this?
import java.text.simpledateformat; import java.util.date; class day{ public static void main( string[] args ){ simpledateformat newdateformat = new simpledateformat("dd/mm/yyyy"); try { date mydate = newdateformat.parse("28/12/2013"); newdateformat.applypattern("eeee dd mmm yyyy"); string isdate = newdateformat.format(mydate); system.out.println(isdate); } catch (exception e) { system.out.println("error. date in wrong format."); } } }
use split()
method :
string []myformat=isdate.split(" "); system.out.println(myformat[2]); system.out.println(myformat[1]); system.out.println(myformat[3]); system.out.println(myformat[0]);
use order whatever order want.
Comments
Post a Comment