English 中文(简体)
Java 停时间
原标题:Java String to Date without time
  • 时间:2010-07-06 22:48:11
  •  标签:
  • java

在 Java,我用一个班子,我需要将体格转换到一个日期格式(d/MM/yyyy)。 我一直在使用简单的表格来编排我的意见,但它正在显示该周的时间、时间区和日期。 这里是我法典的一个要点:

SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
Date date = new Date(); 
do{ 
    y = JOptionPane.showInputDialog(null, 
                                    "Please enter the vehicle s registration date",
                                    "Year?", 
                                    JOptionPane.QUESTION_MESSAGE); 
    try { 
        date = df.parse(y); 
        check = true; 
    } 
    catch (ParseException e) { 
        check = false; 
    } 
} 
while (check == false); 
return date;

Anyone know how I can keep the format to just the date (e.g. 12/3/2000)? Thanks

问题回答

我对@BalusC也有类似的解决办法,但这种办法将提供一种当地依赖的格式:

String dateString = java.text.DateFormat.getDateInstance().format(dateObject);

换言之,你的美国和欧盟客户将采用不同的格式。 他们熟悉其中一人。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签