[英]How do you display Calendar's in Java in a human-readable way?
I have two array lists consisting of Calendar objects. 我有两个由Calendar对象组成的数组列表。 I need these two lists to contain the same objects and in the same order - but this isn't the case. 我需要这两个列表包含相同的对象和相同的顺序-事实并非如此。 I ran the program on debugger mode to check the content of the lists but the object descriptions are gibberish. 我在调试器模式下运行了该程序,以检查列表的内容,但是对象说明很乱。 I just want to know if the year, month and day are the same at each step. 我只想知道每一步的年,月,日是否相同。
This is what my debugger shows: 这是我的调试器显示的内容:
When I click the arrow next to each index to reveal more information I still can't find what I need. 当我单击每个索引旁边的箭头以显示更多信息时,我仍然找不到我需要的东西。 Is there a way around this? 有没有解决的办法? Or perhaps there is another debugging tool that I am unfamiliar with? 也许还有另一个我不熟悉的调试工具? At this stage my debugging skills are limited to placing breakpoints and clicking the bug icon. 在此阶段,我的调试技能仅限于放置断点并单击错误图标。
Appreciate any help. 感谢任何帮助。
java.util.Calendar
in the box "Apply renderer to objects of type..." 在“将渲染器应用于类型...的对象”框中,键入java.util.Calendar
。 new SimpleDateFormat("yyyy-MM-dd").format(getTime())
键入以下表达式(例如): new SimpleDateFormat("yyyy-MM-dd").format(getTime())
If you need to deal with TimeZones, you can use this ampliation to JB Nizet solution: 如果您需要处理TimeZones,可以使用此放大到JB Nizet解决方案:
new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS").format(getTime()) + " " + getTimeZone().getDisplayName(false,TimeZone.SHORT) + " " + getTimeZone().getRawOffset()/3600000
Example output: 输出示例:
Shows the TimeZone name and the offset in hours 显示时区名称和以小时为单位的偏移量
Global configuration is also possible, go here to view all active detail formatter and to add new ones: Preferences > Java > Debug > Detail Formatter 也可以进行全局配置,请转到此处查看所有活动的详细信息格式化程序并添加新的格式化程序: 首选项 > Java > 调试 > 详细信息格式化程序
Qualified type name: java.util.Calendar
合格的类型名称: java.util.Calendar
Detail formatter code snippet returns the String you defined, in my case german format of date + time: 详细格式化程序代码段返回您定义的字符串,在我的情况下为日期和时间的德语格式:
this.get(Calendar.DAY_OF_MONTH ) + "." +
(1 + this.get(Calendar.MONTH ) ) + "." +
this.get( Calendar.YEAR )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.