2016-11-13 4 views
0

내 날짜 형식이 yyyyMMddHHmm이고이 날짜 형식에서 년, 월, 일을 추출하고 1255를 HHmm으로 추가하여 새로운 날짜를 만들려면 에 대해 joda date를 사용하고 있습니다. 시각. 패드가 0에서 1 자릿수로 분 단위로 작성

String date = (Integer.toString(orderDate.getYear()) + Integer.toString(orderDate.getMonthOfYear()) + Integer.toString(orderDate.getDayOfMonth()) + "1259"); 

orderDate = DateTimeFormat.forPattern(DATE_FORMAT).withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone(date1TimeZone))).parseDateTime(String.valueOf(date)); 

그러나

하여 orderDate이 될 일 경우 201,611,051,212 내가 무엇입니까 결과가 달의 값은 내가 05으로 원하는 5 클록 입력에 대한 형식 지정이되어있다 즉 20161151259입니까?

답변

2

Joda docs에서 : "패턴 문자의 수가 형식을 결정합니다."

수정 사항은 Joda metohds를 사용하여 날짜를 수정하여 문자열 조작에 필요한 항목을 고안하지 않아도됩니다.

// your initial date 
    DateTime initialDate = DateTimeFormat.forPattern("yyyyMMddHHmm").parseDateTime("201611051212"); 

    // the operation you're trying emulate by adding a string, better to use specialized method 
    DateTime resultingDate = initialDate.withTime(12, 59, 0, 0); 

    // resulting string representation matches to what you specified as an expected result 
    String result = DateTimeFormat.forPattern("yyyyMMddHHmm").print(resultingDate); 
    Assert.assertEquals("201611051259", result);