for (Map<String,Object> formap:map){ Set keyset = formap.keySet(); Date time=null; String modifykey=null; for(Object key:keyset){ boolean isInstance = formap.get(key) instanceof Date; if (isInstance){ String formatTime=DateUtil.format((Date) formap.get(key),"yyyy-MM-dd HH:mm:ss"); time=DateUtil.parse(formatTime); modifykey=String.valueOf(key); } } if (time!=null) { formap.put(modifykey, time); } }
通过instanceof 判断是否为日期格式,是日期格式则进行时间格式化,然后再用原来的key,重新添加一遍进行覆盖原来的值,实现对于map中对于时间类型的值的格式化。
{ ArgumentIndex }:是从0开始的入参位置索引 { ArgumentIndex , FormatType } { ArgumentIndex , FormatType , FormatStyle }
number:调用NumberFormat进行格式化 date:调用DateFormat进行格式化 time:调用DateFormat进行格式化 choice:调用ChoiceFormat进行格式化
short、medium、long、full、integer、currency、percent、SubformatPattern (子格式模式,形如#.##) 还以str为例,在这个字符串中: 1、{0}和{1,number,short}和{2,number,#.#};都属于FormatElement,0,1,2是ArgumentIndex。 2、{1,number,short}里面的number属于FormatType,short则属于FormatStyle。 3、{1,number,#.#}里面的#.#就属于子格式模式。 指定FormatType和FormatStyle是为了生成日期格式的值、不同精度的数字、百分比类型等等。
1、ArgumentIndex必须是非负整数,它的个数不只限于0到9这10个,它可以用0到9的数字组成,因此可以有好多个,如:
String msg = "{0}{1}{2}{3}{4}{5}{6}{7}{8}"; Object [] array = new Object[]{"A","B","C","D","E","F","G","H","I",}; String value = MessageFormat.format(msg, array); System.out.println(value); // 输出:ABCDEFGHI
while it seems to fit format ‘yyyy-MM-dd‘T‘HH:mm:ss.SSSZ‘
原因:前端对于时间进行了 yyyy-MM-dd hh:mm
的格式化,后端也需要相应的进行格式化不然会出现识别错误如图:
netstat -ano | findstr 8210
结果
taskkill /pid 19432 /f
比如list的大小为2,下标为1 我进行遍历,size为0时,发现不符合我的要求我就进行移除, list的大小就为1,下标就变成了0,原来下标为1的数据就顶替了下标为0的数据 然后for循环就会自动跳出,因为程序认为自己遍历了下表为0的数据,下一条数据又没了 实际上现在下标为0的数据,就是原来的第二条,这样就会造成数据错位
我们就需要用到迭代器iterator,它是一个超级接口,隔离对容器的遍历操作和底层实现,从而解耦。 hasnext()方法是判断是否还有元素 next()方法是获取下一个元素 remove()方法是移除当前的对象