Any chance of formatting Date object returned by resultset getDate() method

徘徊边缘 提交于 2019-12-13 21:07:21

问题


I want to skip the parsing of date and formatting it. Instead i directly want to fetch the date from database in custom format. Is this possible ?


回答1:


Yes, change your SQL query to format the date. For example, if you use oracle, you need to use the function TO_CHAR(dateColumn, 'YYYY/MM/DD'), and that will return a String column with the date formatted as '2012/09/14'.




回答2:


You can set format in your query. (My example is run on sqlserver)

something like..

SELECT CONVERT (VARCHAR, GETDATE(), 103)   

for more detail http://www.sqlusa.com/bestpractices2005/centurydateformat/




回答3:


You need look into the functions provided by the database vendor.

For example, in Oracle we can use the following syntax in the SQL itself

TO_CHAR('date', 'format')

So go thru the documentation database you use.



来源:https://stackoverflow.com/questions/12422370/any-chance-of-formatting-date-object-returned-by-resultset-getdate-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!