Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何格式化时间以出现在JFormattedTextField格式hh:mm中,在它之后没有 AM 或 PM,并且在单个数字小时(例如“09:30”)的情况下为 0?提前致谢。我曾尝试过DateFormat这样做,但它添加了上午/下午。
hh:mm
DateFormat
您可以使用 SimpleDateFormat 对象:
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm"); dateFormat.format(yourDate);
在日期格式构造函数HH中指的是从 0 到 23 的两位数小时,mm指的是分钟。
HH
mm