java 在swings中为jspinner设置时间格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3845374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting Time Format for jspinner in swings
提问by Toman
I am working in a java swing application. In that application i have to take time input from user. I need to make a JSpinner for the time, only in the hh:mm am/pm format. i searched in properties but could not get this format.
我在一个 java swing 应用程序中工作。在那个应用程序中,我必须从用户那里获取时间输入。我需要暂时制作一个 JSpinner,只能采用 hh:mm am/pm 格式。我在属性中搜索,但无法获得这种格式。
Please suggest me some way to display time in hh:mm am/pm format. I thank to all your valuable suggestions.
请建议我一些以 hh:mm am/pm 格式显示时间的方法。我感谢您提出的所有宝贵建议。
采纳答案by Guillaume
You can set an editor and a date model like this:
您可以像这样设置编辑器和日期模型:
SpinnerDateModel model = new SpinnerDateModel();
model.setCalendarField(Calendar.MINUTE);
spinner= new JSpinner();
spinner.setModel(model);
spinner.setEditor(new JSpinner.DateEditor(spinner, "h:mm a"));
回答by Toman
Thanks for answering Guillaume. Your answer is working for me after making a small change i.e.
感谢您回答纪尧姆。你的答案在做了一个小的改变后对我有用,即
spinner.setEditor(new JSpinner.DateEditor(spinner, "h:mm a"));
spinner.setEditor(new JSpinner.DateEditor(spinner, "h:mm a"));
This gives me an appropriate format.
这给了我一个合适的格式。