How do I convert a Joda Time DateTime object into a String in SQL Server format?

后端 未结 4 1027
悲&欢浪女
悲&欢浪女 2020-12-14 08:43

I am using the Joda-Time library in Java, and have a date and time stored as an org.joda.time.DateTime object.

How can I reliably convert this DateTime object into a

4条回答
  •  温柔的废话
    2020-12-14 09:03

    Simply Function

    I use this simple function to get a SQL-friendly date format from a JodaTime DateTime object:

    // Converts a DateTime object into a SQL-format friendly string.
    //
    // Return format looks like this: 2014-01-22 10:05:34.546
    //
    public static String toSql(DateTime dateTime) {
        return new Timestamp( dateTime.getMillis() ).toString();
    }
    

提交回复
热议问题