ある日付(yyyMMdd形式)の文字列から該当の日付0時以上、翌日の0時未満のデータを抽出するための文字列を作成するスマートな方法を知りたいです。
ただし、DBの時刻がGMTのため、GMTに変換する必要があります。
java
1 public void convertGMTTime(String argDate ) throws ParseException{ 2 DateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); 3 dateFormatter.setTimeZone(TimeZone.getTimeZone("JST")); 4 String strStart = argDate + " 00:00:00"; 5 Date startDate = dateFormatter.parse(strStart); 6 7 Calendar nextCal = Calendar.getInstance(); 8 nextCal.setTime(startDate); 9 nextCal.add(Calendar.DAY_OF_MONTH, 1); 10 Date endDate = nextCal.getTime(); 11 12 DateFormat dateFormatter2 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); 13 dateFormatter2.setTimeZone(TimeZone.getTimeZone("GMT")); 14 15 String mStart = dateFormatter2.format(startDate); 16 String mEnd = dateFormatter2.format(endDate); 17 System.out.println(mStart); 18 System.out.println(mEnd); 19 } 20
ちなみに、java6、Linuxです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/13 13:56