SimpleDateFormat的替代方法,用于日期解析

Cri*_*tiL 3 java timezone date simpledateformat

我真的需要SimpleDateFormat的替代品,我正在将许多Strig日期(> 100k)从JST转换为GMT.我遇到的问题是我的代码生成了许多char [],正如我在分析时注意到的那样.对于150k日期,我使用了150MB的内存,这不是一个真正的选择.谢谢.

    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
    sdf.setTimeZone(tz);
    try {
        Date theResult = sdf.parse(dateToConvert);
        SimpleDateFormat rdf = new SimpleDateFormat(resultDateFormat);
        rdf.setTimeZone(resultTz);
        return rdf.format(theResult);
    } catch (ParseException e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

我不能使用Joda时间,所以这对我来说不是一个选择.:(

Ily*_*lya 9

使用joda-time

org.joda.time.format.DateTimeFormatter dtf = 
         org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM-dd");  
    org.joda.time.DateTime date = dtf.parseDateTime(yourDate); // String like 2000-12-12
    date.withZone(yourZone); // org.joda.time.DateTimeZone
Run Code Online (Sandbox Code Playgroud)