简体   繁体   English

如何在jtextfield中以日月(字)和年的格式获取日期

[英]How to get date in jtextfield in format of day month(in words) and year

I am trying to get date in the format of day(digit) month(words), year(digit) but its showing error please help with coding: 我正在尝试以日(数字)月(单词),年(数字)的格式获取日期,但其显示错误请帮助编码:

 lb_date.setText(Calendar.getInstance().getDate().toString());
public menu() {
        initComponents();
        lb_date.setText(Calendar.getInstance().getTime().toString());
        Timer t = new Timer(true);
         lb_des_de.setVisible(false);
         lb_des_cert.setVisible(false);
         lb_des_rep.setVisible(false);
         lb_des_help.setVisible(false);
         lb_entry.setVisible(false);
         lb_cert.setVisible(false);
         lb_report.setVisible(false);
         lb_help.setVisible(false);
        t.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                lb_date.setText(Calendar.getInstance().getTime().toString());
            }
        }, 1000, 1000);
    }

Take a look at the SimpleDateFormat API 看看SimpleDateFormat API

You can do something like: 您可以执行以下操作:

System.out.println(new SimpleDateFormat("MM/dd/yyyy").parse("08/16/2011"));

And you can use these variations: 您可以使用以下变体:

Date and Time Pattern   Result
"yyyy.MM.dd G 'at' HH:mm:ss z"  2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy"  Wed, Jul 4, '01
"h:mm a"    12:08 PM
"hh 'o''clock' a, zzzz" 12 o'clock PM, Pacific Daylight Time
"K:mm a, z" 0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa"  02001.July.04 AD 12:08 PM
"EEE, d MMM yyyy HH:mm:ss Z"    Wed, 4 Jul 2001 12:08:56 -0700
"yyMMddHHmmssZ" 010704120856-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"    2001-07-04T12:08:56.235-0700

or create your own. 或创建自己的。

Try using DateFormat See DateFormat 尝试使用DateFormat请参见DateFormat

SimpleDateFormat format = new SimpleDateFormat( "dd.MMMMM.yyyy" );
Date date = format.parse( myString );

The month will show Up on Words ! 这个月将出现在单词上!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM