ColdFusion - 具有GMT偏移量的DateTime格式 [英] ColdFusion - DateTime Format with GMT offset

查看:126
本文介绍了ColdFusion - 具有GMT偏移量的DateTime格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ColdFusion 10进行一些REST调用,返回的日期使用GMT偏移量。



示例: 2013-03- 25T14:30:40-04:00



我需要将此格式化为两种用途:


  1. 屏幕显示,看起来像 mm / dd / yyyy hh:mm:ss
  2. li>插入到mySQL。

我尝试了各种CF时间/日期函数,但继续得到有效的日期格式



我想也许 #ParseDateTime(i.submitted_at,pop)#处理它与POP但同样的问题。



花了几个小时,现在尝试使用多种变体,现在只需在圈子中进行搜索。任何想法都将非常感激。



谢谢!

解决方案

请查看CFLib上的UDF DateConvertISO8601()



CFLib上的DateConvertISO8601(ISO8601dateString,targetZoneOffset)

ISO 8601并将其转换为ODBC datetime,但可以适应转换为任何你喜欢的。它也将通过指定偏移量转换为您选择的时区中的datetime,即它可以采用GMT的datetime并转换为PT。有关说明,请参阅 http://www.w3.org/TR/NOTE-datetime ISO 8601是表示日期和时间的国际标准。



返回值:

返回日期时间。


源代码可以在我提供的链接中查看。


I am using ColdFusion 10 to make some REST calls and the date returned is using a GMT offset.

Example: 2013-03-25T14:30:40-04:00

I need this formatted for 2 purposes:

  1. Screen Display so it looks something like mm/dd/yyyy hh:mm:ss
  2. To Insert into mySQL.

I have tried a variety of the CF time/date functions but continue to get the "is not a valid date format"

I thought maybe the #ParseDateTime(i.submitted_at,"pop")# would handle it with POP but same issue.

Spent a few hours now trying multiple variations and googling around now just going in circles. Any ideas would be greatly appreciated.

Thanks!

解决方案

Have a look at the UDF DateConvertISO8601() on CFLib.

DateConvertISO8601(ISO8601dateString, targetZoneOffset) on CFLib

Description:
This function take a string that holds a date in ISO 8601 and converts it to ODBC datetime, but could be adapted to convert to whatever you like. It also will convert to a datetime in a timezone of your choice by specifying the offset, i.e. it could take a datetime in GMT and convert to PT. See http://www.w3.org/TR/NOTE-datetime for description of ISO 8601, the International Standard for the representation of dates and times.

Return Values:
Returns a datetime.

The source code is viewable at the link I provided.

这篇关于ColdFusion - 具有GMT偏移量的DateTime格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆