我已搜索但无法找到一种方法只打印特定条目的单键,值对.
map.containsValue(value) or map.containsKey(key)
只会判断特定值或密钥是否可用.我想打印那个特定的键,值对if (value is available)
在其他链接中,如果你不知道键,他们想得到随机值.在这里,我知道关键和价值,并希望打印它以获得特定的关键和价值.
我正在尝试将 java.util.Date 转换为 java.util.Date 但格式不同
10 月 11 日星期三 10:00:00 CDT 2023 --> 2023-10-11T10:00:00.000Z
我展示了很多帖子,并尝试了下面不同的解决方案,但没有运气。
将日期转换为字符串,然后再次转换为日期,但格式不变。
Date utilDate = Wed Oct 11 10:00:00 CDT 2023 // Your java.util.Date
// Define the desired format
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Convert the java.util.Date to a formatted String
String formattedDate = dateFormat.format(utilDate);
System.out.println("Formatted Date String: " + formattedDate);
//convert String again into java.util.Date
// it will return the same utilDate.
Run Code Online (Sandbox Code Playgroud)
还尝试使用 2 SimpleDateFormat 对象。请进一步指导我。