UTC 时间戳格式 - 将包含 UTC 时间日期的字符串分成几部分(经典 asp/vbscript) [英] UTC time stamp format - Split in parts a string containing the UTC time date (classic asp/vbscript)

查看:16
本文介绍了UTC 时间戳格式 - 将包含 UTC 时间日期的字符串分成几部分(经典 asp/vbscript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我的问题被误解了:

I believe that my question is misunderstood:

我的字符串 (uuttcc) 包含 UTC 时间戳格式,在其他页面中使用 JAVASCRIPT 创建.

My string (uuttcc) contains a UTC time stamp format, created in other page with JAVASCRIPT.

我想再次指出,我的字符串包含以下内容:Wed, 10 Jan 2018 17:23:34 UTC

I want to point out again, that my string contain exactly this: Wed, 10 Jan 2018 17:23:34 UTC

有什么办法可以将这个分开--> (Wed, 10 Jan 2018 17:23:34 UTC) 到那个--> (YYYY/MM/DD) ?

Is there any way to break apart this--> (Wed, 10 Jan 2018 17:23:34 UTC) to that--> (YYYY/MM/DD) ?

我有一个包含 UTC 日期/时间的字符串 (uuttcc).

I have a string (uuttcc) that contains the UTC date / time.

:

<%
Response.Write(uuttcc)
%>

给我以下结果:

2018 年 1 月 10 日星期三 17:23:34 UTC

有没有什么特别的方法可以把这个字符串分成 3 个部分,比如经典 ASP/VBScript 中的 DD YY MM??

Is there any particular way to split this string in 3 parts like DD YY MM in classic ASP/VBScript??

推荐答案

不打算回答,但评论中的所有绒毛,使用 Split().

Wasn't going to answer but with all the fluff in the comments, use Split().

Dim input: input = "Wed, 10 Jan 2018 17:23:34 UTC"
Dim parsed: parsed = ParseDateString(input)
Dim output: output = Year(parsed) & "/" & Right("00" & Month(parsed), 2) & "/" & Right("00" & Day(parsed), 2)
Call Response.Write(output)

Function ParseDateString(value)
    'Split the string into manageable chunks.
    Dim parts: parts = Split(value, Chr(32))
    Dim dt, tm
    'Check the split created an array we can work with.
    If IsArray(parts) Then
        'Ignore the first element and use elements 1 - 3 to 
        'create the date structure.
        dt = parts(1) & Chr(32) & parts(2) & Chr(32) & parts(3)
        'Use the 5th element for the time structure.
        tm = parts(4)
        'Stitch them together to form a date variable.
        dt = CDate(dt & Chr(32) & tm)
    Else
        'We don't have a valid format return an empty string.
        dt = Empty
    End If
    ParseDateString = dt
End Function

输出:

2018/01/10

不使用 Split() 怎么办?

主要问题是使用 inbuilt 后,让 CDate() 识别字符串日期函数 将允许您构建您想要的任何格式.

What about not using Split()?

The main issue is getting the string to be recognised by CDate() once you have this using inbuilt date functions will allow you to build whatever format you want.

事实上,使用 CDate() 破坏特定解析的唯一因素是 Wed,UTC,因此您可以使用Mid()InStr()Len() 的组合,如此紧凑示例中所示;

In fact the only thing that breaks that particular parse using CDate() is the Wed, and UTC, so you ignore them using a combination of Mid(), InStr() and Len() as in this compact example;

Dim input: input = "Wed, 10 Jan 2018 17:23:34 UTC"
Dim output: output = CDate(Mid(input, InStr(1, input, ",") + 1, ((Len(input) - 4) - InStr(1, input, ","))))
'You now have a valid `Date` variable you can manipulate to your hearts
'content.
Call Response.Write(output)

10/01/2018 17:23:34

<小时>

有用的链接

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