1

I want to create a parser program. Every two characters in string will cut into a unit of time, for example: "150901184610801" need to be converted to displayed as "Tue Sep 01 18:46 CST 2015".

I know my question is somewhat complex, so I would like to be divided into different blocks sequentially solve the problem.

The first problem is:

How to use JAVA to format string follow a rule : each two word element cut into a variable, so I can manipulate variables such as yy (15), mm (09), dd (01), hh (18), ss (46).

Thanks again for any suggest.

CodeLife
  • 13
  • 3
  • 3
    Have a look at `SimpleDateFormat`. Use a `SimpleDateFormat` to parse your text into a `Date` object and then use another to format to your specifications – MadProgrammer Sep 03 '15 at 09:42

2 Answers2

1

Actually seems quite simple:

String s = "150901184610801";
SimpleDateFormat df = new SimpleDateFormat("yyMMddhhmmssS");
System.out.println(df.parse(s));

OUTPUT:

Tue Sep 01 18:46:10 CEST 2015

Check SimpleDateFormat API

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
0

You can use a SimpleDateFormat

Jib'z
  • 953
  • 1
  • 12
  • 23