[JAVA] When the month of the date is acquired, the January shift

This is a common bug, and when the month of the date is acquired, the January shift occurs. Specification problem.

For javascript

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;
}

For java

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

When the month of the date is acquired, the January shift
When the hover of Eclipse is hard to see
In Time.strptime,% j (total date of the year) is
When using the constructor of Java's Date class, the date advances by 1900.
The idea of cutting off when the error is not resolved
[Rails] When the layout change of devise is not reflected
[Swift] Get the timing when the value of textField is changed
'% 02d' What is the percentage of% 2?
The design concept of Java's Date and Time API is interesting
Investigation method when the CPU of the server running java is heavy
Incident (rails) that is logged out when user editing of the application
When the appearance of the input form is broken on the page after rendering
Error when the member of Entity class used in SpringWebFlux is final
Solution of component that saves cookie when Talend WebAPI data is acquired
When the bean class name is duplicated
What is testing? ・ About the importance of testing
LIMIT 11 when data is acquired by irb
What is the data structure of ActionText?
[swift] How to control the behavior when the back button of NavigationBar is pressed
[Ruby] Meaning of &. How to avoid the error when the receiver (object) is nil
Upcast (Java) that can reduce the amount of change when the specification is changed
[Java] Calculate the day of the week from the date (Calendar class is not used)
What is JSP? ~ Let's know the basics of JSP !! ~
ActiveSupport underscore is not the inverse of camelize
f.Validation when "Please select" of collection_select is selected
The order of Java method modifiers is fixed
The date time of java8 has been updated
The official name of Spring MVC is Spring Web MVC
The story of initializing Money :: Currency when testing
When the project is not displayed in eclipse