SimpleDateFormatのk
人の書いたソースを見ていたら、SimpleDateFormatの書式に"kk:mm"というのがあって、kってなんだろうと調べてみたら時間を1-24で表現する書式のようだ。
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2006);
cal.set(Calendar.MONTH, Calendar.DECEMBER);
cal.set(Calendar.DAY_OF_MONTH, 31);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
Date date = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd kk:mm");
System.out.println(sdf.format(date));
sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
System.out.println(sdf.format(date));
2006/12/31 24:00 2006/12/31 00:00
なんか日付との整合性が合わないな。これって本当は2006/12/30 24:00じゃないの? kを使う時は日付を使用してはいけないのかな。
50万hit
カウンタが50万を越えた。もっともほとんどはRSSリーダからのポーリングによるものと思われるので、実際のPVはずっと少ないんだろうけど。
というわけで、これからもよろしくお願いいたします。
ファイルコピー
SHISHI@東京さんからヒントをいただいたので、ちょっとNIO版を書き換えてみた。
public class CopyByNio2 {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
String copyFrom = args[0];
String copyTo = args[1];
int bufferSize = 32 * 1024;
if (args.length > 2) {
bufferSize = Integer.parseInt(args[2]) * 1024;
}
if (bufferSize <= 0)
throw new IllegalArgumentException("Invalid buffer size(=" + bufferSize + ").");
FileChannel in = null;
FileChannel out = null;
try {
in = new FileInputStream(copyFrom).getChannel();
out = new FileOutputStream(copyTo).getChannel();
long size = in.size();
long offset = 0;
while (size > 0) {
long writtenSize = in.transferTo(offset, size, out);
offset += writtenSize;
size -= writtenSize;
}
}
catch (IOException ex) {
ex.printStackTrace();
}
finally {
if (in != null) {
try {in.close();}
catch (IOException ex) {ex.printStackTrace();}
}
if (out != null) {
try {out.close();}
catch (IOException ex) {ex.printStackTrace();}
}
System.console().printf("Elapsed %,d%n",System.currentTimeMillis() - startTime);
}
}
}
あってるかな? 一応コピーされたファイルの内容を確認したので、大丈夫そうだけど... 結果は0.5秒くらい速くなったけど、この程度だと大差無しかなぁ。というか前回のテストでは25秒くらいだったのが、今回はどれも10秒くらいで終わるのは、どういうわけだろう。前回は、なぜかキャッシュが効いていなかったようだ。バックグランドで動いていたアプリケーションのせいだろうか。





