Chinaunix

标题: 请教:perl中如何显示数据库中日期格式 [打印本页]

作者: dkmilk    时间: 2006-04-11 21:32
标题: 请教:perl中如何显示数据库中日期格式
如我从数据库中查询到一日期对像
如何把这个日期对像格式化成我想要的格式?

还有,请教,我传入一个日期,如果对这个日期格式化?
作者: 兰花仙子    时间: 2006-04-11 22:49
原帖由 dkmilk 于 2006-4-11 21:32 发表
如我从数据库中查询到一日期对像
如何把这个日期对像格式化成我想要的格式?

还有,请教,我传入一个日期,如果对这个日期格式化?


你传入的日期是什么格式?又想输出成什么格式呢?
作者: ulmer    时间: 2006-04-11 23:23
原帖由 dkmilk 于 2006-4-11 21:32 发表
如我从数据库中查询到一日期对像
如何把这个日期对像格式化成我想要的格式?

还有,请教,我传入一个日期,如果对这个日期格式化?


Firstly you should know the date format in your SQL database.
For erample, most of date format from SQl set as ISO-Style like "YYYY-MM-DD HH::MM:SS".
Which format is totally depending on your database.

You can use sql command to test it. for example under my PostgreSQL type:

  1. test=> select now();
  2.               now
  3. -------------------------------
  4. 2006-04-11 17:16:23.784875+08
  5. ^date^^^|^time^^|^timezone^
复制代码


If you get this returned string from sql and you can use perl's substr(),
split(), regexp ...etc to fetch date, time and time zone. reverse too.

Best regards, ulmer
作者: ulmer    时间: 2006-04-11 23:26
原帖由 dkmilk 于 2006-4-11 21:32 发表
如我从数据库中查询到一日期对像
如何把这个日期对像格式化成我想要的格式?

还有,请教,我传入一个日期,如果对这个日期格式化?


Firstly you should know the date format in your SQL database.
For erample, most of date format from SQl set as ISO-Style like "YYYY-MM-DD HH::MM:SS".
Which format is totally depending on your database.

You can use sql command to test it. for example under my PostgreSQL type:

  1. test=> select now();
  2.               now
  3. -------------------------------
  4. 2006-04-11 17:16:23.784875+08
  5. ^date^^^|^time^^|^timezone^
复制代码


If you get this returned string from sql and you can use perl's substr(),
split(), regexp ...etc to fetch date, time and time zone. reverse too.

Best regards, ulmer
作者: apile    时间: 2006-04-12 08:46
1.数据库的话..找一个env variable类似DBDATE或DBTIME的...设定一下...
每个db不大一样...
2.日期格式的转换,自己写就行了.这应该很简单吧...
作者: ulmer    时间: 2006-04-12 21:14
原帖由 dkmilk 于 2006-4-11 21:32 发表
如我从数据库中查询到一日期对像
如何把这个日期对像格式化成我想要的格式?

还有,请教,我传入一个日期,如果对这个日期格式化?


Firstly using SQL to read what date format do you have.
For example, from my PostgreSQL:
test=> select now();
              now
-------------------------------
2006-04-12 15:14:14.594163+02


You can see the date format (usually is ISO-format, but it's different from various database)
With those date formate you can use perl's method substr(), split(), regexp, ... etc
to process and modify it.

Best regards, ulmer




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2