2011-03-07 2 views
0
 PreparedStatement pStmt = con.prepareStatement("insert into mydate values(?,?)"); 

     java.util.Date now = new java.util.Date(); 

     pStmt.setDate(1, new java.sql.Date(now.getTime())); 


     pStmt.setTimestamp(2, new java.sql.Timestamp(now.getTime())); 
      pStmt.executeUpdate(); 

QUERY1 : 나는 사용자가 자신의 comments.also을 게시 할 때 내가 보여주고 싶은 시간을 표시 할 .I 코멘트 모듈을 게시 만드는 오전 그들이 의견을 게시 한 후 시간이 지났습니다. 2 일 전, 5 분 전 등는 현재 시간과 날짜의 항목 경과 시간을 계산

QUERY2 : 또한 날짜 형식을 dd/mm/yyyy로 변경하고 싶습니다. 날짜를 표시하기 위해

답변

0

당신이 org.apache.commons.lang.time를 사용할 수있는 시간 간격을 위해 java.text.SimpleDateFormat에 또는 org.apache.commons.lang.time.FastDateFormat

을 사용할 수 있습니다 포맷 .DurationFormatUtils 여기

는 샘플입니다

//this will get the date in format dd/mm/yyyy 
FastDateFormat fmt = FastDateFormat.getInstance("dd/MM/yyyy"); 
String txt = fmt.format(date); 

//this will get the interval 
long ival = System.currentTimeMilis()-date.getTime(); 
String interval = DurationFormatUtils.formatDurationWords(ival, true, true); 
+0

당신이 예를 – Prerna

+0

문자열 간격의 도움 = DurationFormatUtils.formatDurationWords (ival, 사실, 사실)로 설명 할 수있다; 라인이 넷빈에서 오류를 보여줍니다. – Prerna

+0

문자열 간격 = DurationFormatUtils.formatDurationWords (ival, true, true); 이 넷빈에 오류가 있습니다. – Prerna

관련 문제