2017-03-10 1 views
1

JSON에서 밀리 초 (1488520800000)를 추출하여 형식화 된 날짜 (2017-03-02)로 변수에 넣는 것 같습니다. 난 못해 3 월 2 일 2017 :jmeter 변수를 밀리 초 단위로 변환하십시오.

ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval  Sourced file: inline evaluation of: ``import java.text.*; import java.util.*; log.info("value for variable: 14885208 . . . '' : Typed variable declaration : Method Invocation source.parse 

어떤 이상한 것은 내가 유사한 코드가 같은 추출 된 날짜를 잘 작동하는 가지고 있다는 것입니다 : 여기

import java.text.*; 
import java.util.*; 

SimpleDateFormat source = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); 
SimpleDateFormat target = new SimpleDateFormat("yyyy-MM-dd"); 
Date date = source.parse(vars.get("varReviewDatevalue")); 
String newDate = target.format(date); 
vars.put("varFormattedReviewdateValue",newDate); 

내가 얻을 오류 발생 : 여기 내 코드는 밀에서 표현 된 날짜가 날짜로 변환되지 않는 이유를 찾아냅니다. 어떤 아이디어?

+0

의 사용 가능한 복제 [자바에서 날짜 전에 currentTimeMillis을 변환하는 방법?] (HTTP : // 유래. com/questions/8237193/how-to-convert-currenttimemillis-to-a-date-in-java) –

답변

1

잘못된 jmeter 요소를 사용하고있었습니다. 이 포스팅은 많이 도와주었습니다 : JMeter: Converting extracted time stamp value to date format

은 내가 JSR223 샘플러에이 코드를 넣어 모든

근무
import java.text.*; 
long timeStamp = Long.parseLong(vars.get("varReviewDatevalue")); 
Date date = new Date(timeStamp); 
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 

TimeZone tzInAmerica = TimeZone.getTimeZone("America/Denver"); 
formatter.setTimeZone(tzInAmerica); 
String dateFormatted = formatter.format(date); 
vars.put("varFormattedReviewdateValue", dateFormatted); 
log.info(dateFormatted); 
log.info(vars.get("varFormattedReviewdateValue")); 
관련 문제