当我将这些int var链接为字符串时,为什么会添加int var?

Hel*_*oCW -1 java android

我希望生成一个基于文件名的日期,我认为字符串名称将返回20151027_161053.mp4.

实际上它返回2051_161053.mp4,似乎年,月,日都加了2051 = 2015 + 10 + 27-1,但似乎没有添加161053.

我的代码有什么问题?谢谢!

    Calendar c = Calendar.getInstance();

    int year=c.get(Calendar.YEAR);
    int month=c.get(Calendar.MONTH);
    int day=c.get(Calendar.DAY_OF_MONTH);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    int sencond=c.get(Calendar.SECOND);

    String name;
    name=year+month+day+"_"+hour+minute+sencond+".mp4";
Run Code Online (Sandbox Code Playgroud)

Bla*_*elt 5

使用SimpleDateFormat以您需要的格式检索名称.

SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd_hhmmss", Locale.US)
String name = f.format(c.getTime());
Run Code Online (Sandbox Code Playgroud)

您还可以在此处阅读有关java的运算符优先级的信息