서버가 1390361405210 + 0530으로 보내는 중입니다. 그렇다면이 날짜를 변환하려면 0530을 1390361405210에 추가하고 날짜와 시간을 계산해야합니까?밀리 초를 날짜로 변환합니다
상관 제안 appreciated.Thanks되어야
서버가 1390361405210 + 0530으로 보내는 중입니다. 그렇다면이 날짜를 변환하려면 0530을 1390361405210에 추가하고 날짜와 시간을 계산해야합니까?밀리 초를 날짜로 변환합니다
상관 제안 appreciated.Thanks되어야
public static void main(String[] args)
{
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
long milliSeconds=1390361405210L;
Date date = new Date(milliSeconds);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
System.out.println(formatter.format(calendar.getTime()));
System.out.println(formatter.format(date));
}
저희 String
의 첫 번째 부분은 밀리 초 the epoch 보낸 것을 고려하고, 두 번째 부분은 그 경우, IST의 시간대를 표시 (이면
final String jsonDate = "1390361405210+0530";
final Date date = new Date(Long.parseLong(jsonDate.substring(0, jsonDate.length() - 5)));
final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL, Locale.US);
format.setTimeZone(TimeZone.getTimeZone("GMT" + jsonDate.substring(jsonDate.length() - 5)));
System.out.println(format.format(date));
출력 :
, 인도 표준시),이 같은 읽을 수있는 날짜를 얻을 수 있습니다2014 년 1 월 22 일 9:00:05 GMT + 05 : 30
어때?
long currentDateTime = 1390361405210L;
Date currentDate = new Date(currentDateTime);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss Z");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+530"));
System.out.println(sdf.format(currentDate));
아니, 당신은 (530)을 추가하지 않으 당신 * 힘 * 5 시간 30 초 추가 (또는 빼기) 할,하지만 매우 다릅니다. 샘플을 나타 내기위한 날짜/시간을 정확히 아십니까? (특히 UTC인지 아닌지를 알아야합니다 ...) 결과에 UTC 오프셋을 유지해야합니까? –
실제로 서버는 1390361405210 만 전송하지만 json 응답시에는 자동으로 0530이 추가됩니다. 5 시간 30 분을 더하거나 뺄 필요가 없다는 뜻입니까? – PPD
컨텍스트가 무엇인지는 분명하지 않습니다. 서버 란 무엇입니까? JSON은 무엇을 만드나요? 무엇을 성취하려고합니까? 더 많은 문맥을 제공하거나 도움을 받기가 매우 어렵습니다. –