This is a common bug, and when the month of the date is acquired, the January shift occurs. Specification problem.
The getMonth () method returns a 0-based value that represents the "month" of the specified date, based on local time. So you need to format it as below
function getTiffFileName(areaID, pointID, theme, func){
var temple = config.tiff_file_name_format;
var date = new Date();
//var date = new Date('October 3, 2019 11:02:20');
return temple.split('{areaID}').join(areaID)
.split('{pointID}').join(pointID)
.split('{theme}').join(theme)
.split('{func}').join(func)
.split('{yyyy}').join(date.getFullYear())
.split('{mm}').join(dateToString(date.getMonth() + 1))
.split('{dd}').join(dateToString(date.getDate()))
.split('{HH}').join(dateToString(date.getHours()))
.split('{MM}').join(dateToString(date.getMinutes()))
.split('{SS}').join(dateToString(date.getSeconds()))
.split('{TT}').join(date.getTime());
}
function dateToString(val){
if(val < 10){
val = '0' + val;
}
return val;
}
At the time of Calendar.MONTH, it is necessary to format as above
private String getBinaryFileName(){
Calendar calendar = Calendar.getInstance();
String yyyy = toString(calendar.get(Calendar.YEAR),4);
String mm = toString(calendar.get(Calendar.MONTH) + 1,2);
String dd = toString(calendar.get(Calendar.DAY_OF_MONTH),2);
String HH = toString(calendar.get(Calendar.HOUR_OF_DAY),2);
String MM = toString(calendar.get(Calendar.MINUTE),2);
String SS = toString(calendar.get(Calendar.SECOND),2);
String TT = Integer.toString(calendar.get(Calendar.MILLISECOND));
return RelayConst.tsunamiinfo_fortiff_path + RelayConst.tsunamiinfo_fortiff_format.replaceAll("\\{yyyy\\}", yyyy)
.replaceAll("\\{mm\\}", mm)
.replaceAll("\\{dd\\}", dd)
.replaceAll("\\{HH\\}", HH)
.replaceAll("\\{MM\\}", MM)
.replaceAll("\\{SS\\}", SS)
.replaceAll("\\{TT\\}", TT);
}
private String toString(int val, int digits) {
String str = Integer.toString(val);
if (str.length() > digits) {
str = str.substring(str.length() - digits);
}
while (str.length() < digits) {
str = "0" + str;
}
return str;
}
Recommended Posts