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

查看:443
本文介绍了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.

我想再次指出,我的字符串恰好包含以下内容:星期三,2018年1月10日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) ?

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

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()怎么办?

主要问题是,一旦您使用内置日期函数将字符串获得CDate()识别,它将被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天全站免登陆