English 中文(简体)
Convert String to java.sql. 日期和java.sql。 时间
原标题:Convert String to java.sql.Date and java.sql.Time

如果我有这样的方法:

public static String convertDateTimeToString(DateTime dt) {
    return dt.getDate() + " " + dt.getTime();
}

采用<代码>Datetime本人的物体,其中载有java.sql.Datejava.sql. 时间,是扭转这一进程的最佳途径,以便我能够附上<条码>java.sql.Date和<条码>。 时间

或者,如果<代码>Datetime dt?

如不参考<代码>javautil即可做到这一点。 日期:。

问题回答

参看SimpleDateFormat。 http://java.sun.com/docs/books/tutorial/i18n/format/simpleDateFormat.html

你们需要这样的东西:

String datetimeString;
Date result;
SimpleDateFormat formatter = new SimpleDateFormat("EEE d MMM yy hh:mm:ss");
result = formatter.parse (datetimeString);

您可使用t ValueOf,java.sql。 时间将“努力”改为“java.sql.time”,并使用





相关问题
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 ...

热门标签