protected String formatDateStr2 ( String str ) { // Initial Calendar object Calendar cal = Calendar . getInstance ( ) ; str = str . replaceAll ( "/" , "" ) ; try { // Set date with input value cal . set ( Integer . parseInt ( str . substring ( 0 , 4 ) ) , Integer . parseInt ( str . substring ( 4 , 6 ) ) - 1 , Integer . parseInt ( str . substring ( 6 ) ) ) ; // translatet to yyddd format return String . format ( "%1$02d%2$03d" , cal . get ( Calendar . YEAR ) % 100 , cal . get ( Calendar . DAY_OF_YEAR ) ) ; } catch ( Exception e ) { // if tranlate failed, then use default value for date //sbError.append("! Waring: There is a invalid date [").append(str).append("]\r\n"); return formatDateStr2 ( defValD ) ; } }
Translate data str from yyyymmdd to yyddd