datetime - Java SimpleDateFormat issue with kk hour formatting -
i understand kk supposed cause hours range 1-24. however, there seems issue in how days change in formatting.
here example code , it's output illustrate point:
long hour = 3600000l; simpledateformat kkformat = new simpledateformat("yyyy-mm-dd kk"); simpledateformat hhformat = new simpledateformat("yyyy-mm-dd hh"); date date = kkformat.parse("2015-05-20 21"); for(int i=0; i<5; i++){ system.out.println(kkformat.format(new date(date.gettime() + * hour))); system.out.println(hhformat.format(new date(date.gettime() + * hour))); system.out.println(); }
this generates following output:
2015-05-20 21 2015-05-20 21 2015-05-20 22 2015-05-20 22 2015-05-20 23 2015-05-20 23 2015-05-21 24 2015-05-21 00 2015-05-21 01 2015-05-21 01
the issue see "2015-05-21 24" should date not formatted "2015-05-20 24".
thanks clarifications.
edit: in answer dan getz i'm trying create file names iterate follows:
2015052023.txt
2015052024.txt
2015052101.txt
what day is, while dependent on time zone, independent of way hours written. if date 21st, date 21st, end of story. writing "12am" "00" or "24" irrelevant this.
perhaps you're forgetting hour has 60 different minutes in it? it's not first instant clock strikes midnight, it's whole hour after we're talking about, part of next 24-hour day.
i never use 24 times after 12am because of ambiguity. perhaps edit question why you'd want use 24 hours this? data model time stamps down millisecond or similar? or hoping store , print else?
Comments
Post a Comment