0

I have a string of time format 2015-08-14T06:00:00+08:00 and I want to convert that to timeStamp but with:

public static Long convertTimeStringToTimeStampMilSec(String timeStr){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-ddTHH:MM:SS+08:00");
        try {
            Date d = dateFormat.parse(timeStr);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            return c.getTimeInMillis();
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
}

And get exception:

Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'T'
    at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:845)
    at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:659)
    at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:585)
    at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:560)

How to deal with this?

armnotstrong
  • 8,605
  • 16
  • 65
  • 130

1 Answers1

3

Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'T'

It should be

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+08:00");

Quoted sequences in the format, such a 'T', which is treated as a literal.

SatyaTNV
  • 4,137
  • 3
  • 15
  • 31