[英]convert a date object to Oracle timestamp type string
I want to convert a date object, ex: new Date()
, to a string which has a format like Oracle's time stamp type, ex: 21-OCT-13 11.08.13.858000000 AM
. 我想将日期对象(
ex: new Date()
转换为具有类似于Oracle时间戳类型的格式的字符串, ex: 21-OCT-13 11.08.13.858000000 AM
。 I know I could just get each piece of information in the date object like day, month, year, hour, minute, ...
to form the Oracle format string but I really want to know is there a utility to do that instead? 我知道我可以在日期对象(如
day, month, year, hour, minute, ...
等)中获取每条信息day, month, year, hour, minute, ...
以形成Oracle格式字符串,但我真的想知道是否有实用程序可以代替?
Using SimpleDateFormat#format()
you would print a Date
as 使用
SimpleDateFormat#format()
您可以将Date
打印为
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy hh.mm.ss.SSSSSSSSS a");
System.out.println(sdf.format(new Date()).toUpperCase());
Output : 输出:
21-OCT-13 10.01.38.000000614 AM
See JavaDocs for Date and Time patterns. 有关日期和时间模式,请参见JavaDocs 。
Try taking a look at SimpleDateFormats - That would be your best bet and easiest way of doing it. 尝试看看SimpleDateFormats-这将是您最好的选择,也是最简单的方法。
Eg: 例如:
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss"); //Hours:Minutes:Seconds
String strDate = dateFormat.format(date);
Use SimpleDateFormat . 使用SimpleDateFormat 。
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("your_format_here"); // dd/MM/yy h:mm:ss a
String formattedDate = sdf.format(date);
System.out.println(formattedDate);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.