parsing - How to Read Time and Date from Text File in Java 5? -
i'm trying read data plain text file using java 5 se. data in following formats:
10:48 07/21/2011
i've looked dateformat , simpledateformat, can't figure out straight-forward way of reading data date object.
here's have far:
import java.io.file; import java.io.bufferedreader; import java.io.filereader; import java.io.ioexception; import java.text.simpledateformat; import java.util.date; class pim { file datafile; bufferedreader br; string lineinput; date inputtime; date inputdate; public pim() { datafile = new file("c:\\data.txt"); try { br = new bufferedreader(new filereader(datafile)); lineinput = br.readline(); inputtime = new date(lineinput); lineinput = br.readline(); inputdate = new date(lineinput); br.close(); } catch (ioexception ioe) { system.out.println("\n error data.txt file occured."); } } }
am on right track here? what's best way this?
first concat 2 lines have this: string date = "07/21/2011 10:48 am"
dateformat formatter = new simpledateformat("mm/dd/yy h:mm a"); date date = (date)formatter.parse(date);
this should work, can refer simpledateformat api more options.
Comments
Post a Comment