ColdFusion 未正确解释 CFDirectory 中的日期时间
我们在 Windows Server 2003 上安装了 Coldfusion
未送达邮件上的 CFDirectory 转储返回以下内容:
但是问题出在迭代此查询时,当我转储日期时:
#dateFormat(mailStubs.DateLastModified,'dd-mmm-yyyy')#
这就是我得到的:
11-Nov-2026
2027 年 11 月 11 日
2028 年 11 月 11 日
2029 年 11 月 11 日
2029 年 11 月 11 日
2029 年 11 月 11 日
1930 年 11 月 11 日
1930 年 11 月 11 日
1930 年 11 月 11 日
1930 年 11 月 11 日
1930 年 11 月 11 日
1930 年 11 月 11 日
1930 年 11 月 11 日
1930 年 11 月 11 日
这样做:
datediff("n", mailStubs.DateLastModified, now())
now() 是 2011 年 11 月 30 日,可以说下午 2:00 给了我非常奇怪的结果
这只发生在 Windows server 2003(我们的生产服务器)上,它在我的本地系统上运行良好( XP)
有什么想法吗?
We have Coldfusion installed on Windows Server 2003
A dump of CFDirectory on the undelivered mail returns the following:
But the problem is upon iterating this query, when I dump the date with:
#dateFormat(mailStubs.DateLastModified,'dd-mmm-yyyy')#
This is what I get:
11-Nov-2026
11-Nov-2027
11-Nov-2028
11-Nov-2029
11-Nov-2029
11-Nov-2029
11-Nov-1930
11-Nov-1930
11-Nov-1930
11-Nov-1930
11-Nov-1930
11-Nov-1930
11-Nov-1930
11-Nov-1930
So doing:
datediff("n", mailStubs.DateLastModified, now())
now() being 30th Nov 2011 lets say 2:00 PM gives me very weird results
This only happens on Windows server 2003 (Our production server), it worked fine on my local system (XP)
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一个非常古老的线程,但是...
cfdirectory
返回一个本地化日期字符串(不是日期对象)。因此,您应该使用 LS(区域设置敏感)日期函数来解析它。原因是标准 CF 日期函数(DateFormat
、ParseDateTime
...)始终使用美国日期约定。由于美国惯例是月份在前,因此如果您传入“dd-mm-yyyyy”日期字符串,您将得到错误的结果。 (至少在某些时候。)I know this is a really old thread, but ...
cfdirectory
returns a localized date string (not date object). So you should be using theLS
(locale sensitive) date functions to parse it. The reason is that the standard CF date functions (DateFormat
,ParseDateTime
, ...) always use U.S. date conventions. Since the U.S. convention is month first, you will get the wrong results if you pass in a "dd-mm-yyyyy" date string. (At least some of the time.)看起来您修改的日期以 dateFormat() 无法识别的格式出现。
尝试使用 java SimpleDateFormat 转换为 cf“{ts}”日期。
您创建一个 SimpleDateFormat + ParsePosition,然后在循环中调用 sdf.parse() 方法并使用 pp.setIndex(0) 重置位置。
如果您希望它仅在 Windows 2003 服务器上运行,请检查服务器范围
server.os.version
简单演示其工作原理:
SimpleDateFormat 是一个具体类,用于以区域设置敏感的方式格式化和解析日期。它允许格式化(日期 -> 文本)、解析(文本 -> 日期)和标准化。
http://docs.oracle.com/javase /1.4.2/docs/api/java/text/SimpleDateFormat.html
ParsePosition 是 Format 及其子类使用的一个简单类,用于在解析期间跟踪当前位置。
http://docs.oracle.com/javase /1.4.2/docs/api/java/text/ParsePosition.html
Looks like your modified dates are coming out in a format that dateFormat() doesn't recognise.
Try using a java SimpleDateFormat to convert to a cf "{ts}" date.
You create a SimpleDateFormat + ParsePosition, then in your loop, call the sdf.parse() method and reset the position with pp.setIndex(0)
If you want this to only run on your windows 2003 server, check the server scope
server.os.version
Simple demonstration of it working:
SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization.
http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
ParsePosition is a simple class used by Format and its subclasses to keep track of the current position during parsing.
http://docs.oracle.com/javase/1.4.2/docs/api/java/text/ParsePosition.html