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

时间:2022-08-25 10:52:05

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);
    }

2 个解决方案

#1


0  

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.

或创建自己的。

#2


0  

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 !

这个月会出现在单词上!

#1


0  

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.

或创建自己的。

#2


0  

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 !

这个月会出现在单词上!