现成的方法没用过,不过可以自己写一个呗,掐头去尾后再用format即可。
Function GetTimes(ByVal GmtTime As String) As String
If Len(Trim(GmtTime)) = 0 Then Exit Function
If InStr(1, GmtTime, " gmt", vbTextCompare) = 0 Then Exit Function
Dim t1 As String
t1 = Replace(GmtTime, "gmt", "", 1, , vbTextCompare)
t1 = Right$(t1, Len(t1) - InStr(1, t1, ",", vbTextCompare))
GetTimes = Format$(t1, "yyyy-mm-dd hh:nn:ss")
End Function
Sub tes()
Debug.Print GetTimes("Tue, 23 Sep 2014 17:16:52 GMT")
End Sub
Function GetTimes(ByVal GmtTime As String) As String
If Len(Trim(GmtTime)) = 0 Then Exit Function
If InStr(1, GmtTime, " gmt", vbTextCompare) = 0 Then Exit Function
Dim t1 As String
t1 = Replace(GmtTime, "gmt", "", 1, , vbTextCompare)
t1 = Right$(t1, Len(t1) - InStr(1, t1, ",", vbTextCompare))
GetTimes = Format$(t1, "yyyy-mm-dd hh:nn:ss")
End Function
Sub tes()
Debug.Print GetTimes("Tue, 23 Sep 2014 17:16:52 GMT")
End Sub
解决方案 »
- datagrid 下标越界(在线等!!)请大家多帮忙啊!
- 如何获取某应用程序中的文本框内容
- 找出各个月的记录!!!
- 如何在运行时用API设置TextBox可显示多行文本?(第一个给出正确代码300分)
- 怎么得到Excel工作表的行和列的值?
- vb高手请来vb高手请来vb高手请来vb高手请来
- 特别着急!如何对netmeeting进行二次开发??给个例子
- 如何让子窗体在顶层并最大化?
- QuicBasic的一个问题。老鸟来看看。
- ?请问各位老大 给小的推荐一个好的打包程序 谢谢了!!
- SQL语句读取access读取数据库时,居然不能读取名为NO的列,怎么解决?
- VB接收串口数据部正常,但串口调试器是正常的,C#程序也没问题
你可以把前面的星期和后面的时区去掉之后再转换.前面是逗号隔开的, 后面是空格隔开的
先用split函数分隔再转换吧.
#include <string.h>
#include <time.h>
struct tm st;
time_t tt;
char timstr[40];
char tmpbuf[128];
char c;
int t;
int AP() {
if ('P'==c || 'p'==c) {st.tm_hour+=12;return 1;}
if ('A'==c || 'a'==c) return 1;
return 0;
}
int dtparse() {
if (7==sscanf(timstr,"%d/%d/%4d %d:%d:%d %c",&st.tm_mday,&st.tm_mon ,&st.tm_year,&st.tm_hour,&st.tm_min,&st.tm_sec,&c)) if (AP()) goto STEP2;
if (6==sscanf(timstr,"%d/%d/%4d %d:%d%c" ,&st.tm_mday,&st.tm_mon ,&st.tm_year,&st.tm_hour,&st.tm_min ,&c)) if (AP()) goto STEP1;
if (6==sscanf(timstr,"%4d/%d/%d %d:%d %c" ,&st.tm_year,&st.tm_mon ,&st.tm_mday,&st.tm_hour,&st.tm_min ,&c)) if (AP()) goto STEP1;
if (5==sscanf(timstr,"%d.%d.%4d %d:%d" ,&st.tm_mon ,&st.tm_mday,&st.tm_year,&st.tm_hour,&st.tm_min )) goto STEP1;
if (6==sscanf(timstr,"%4d-%d-%d %d:%d:%d" ,&st.tm_year,&st.tm_mon ,&st.tm_mday,&st.tm_hour,&st.tm_min,&st.tm_sec )) goto STEP2;
STEP1:
st.tm_sec=0;
STEP2:
st.tm_year-=1900;
if (st.tm_mon>12) {t=st.tm_mon;st.tm_mon=st.tm_mday;st.tm_mday=t;}
st.tm_mon-=1;
tt=mktime(&st);
if (-1!=tt) {
strftime(tmpbuf,128,"%Y-%m-%d %H:%M:%S",localtime(&tt));
return 1;
} else {
printf("[%s] is Invalid time string!\n",timstr);
return 0;
}
}
int main() {
strcpy(timstr,"10.01.2012 15:43" );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
strcpy(timstr,"8/11/2006 11:10AM" );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
strcpy(timstr,"2006/10/31 04:50 PM" );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
strcpy(timstr,"1/6/2010 5:20:12 PM" );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
strcpy(timstr,"13/12/2012 11:16:17 a.m.");if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
strcpy(timstr,"2013-06-08 09:56:59" );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);
return 0;
}
//[10.01.2012 15:43] is [2012-10-01 15:43:00]
//[8/11/2006 11:10AM] is [2006-11-08 11:10:00]
//[2006/10/31 04:50 PM] is [2006-10-31 16:50:00]
//[1/6/2010 5:20:12 PM] is [2010-06-01 17:20:12]
//[13/12/2012 11:16:17 a.m.] is [2012-12-13 11:16:17]
//[2013-06-08 09:56:59] is [2013-06-08 09:56:59]
//
#include <string.h>
#include <time.h>
#include <sys/timeb.h>struct tm st;
time_t tt;
char mon[4];
char mn[12][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int i;
char timstr[27];
char tmpbuf[128];
struct _timeb tb;
int tz;
char c;void main() {
strcpy(timstr,"08/Dec/2011:15:25:03 +0800");
sscanf(timstr,"%2d/%3s/%4d:%2d:%2d:%2d",&st.tm_mday,mon,&st.tm_year,&st.tm_hour,&st.tm_min,&st.tm_sec);
for (i=0;i<12;i++) if (0==stricmp(mn[i],mon)) {st.tm_mon=i; break;}
st.tm_year-=1900;
tt=mktime(&st);
if (-1!=tt) {
strftime(tmpbuf,128,"%Y-%m-%d %H:%M:%S\n",localtime(&tt));
printf(tmpbuf);//2011-12-08 15:25:03
} else {
printf("[%s] is Invalid time string!\n",timstr);
} _ftime(&tb);
strftime(tmpbuf,128,"%m/%b/%Y:%H:%M:%S",localtime(&tb.time));
tz=-tb.timezone;
c=(tz>0)?'+':'-';
tz=(tz>0)?tz:-tz;
sprintf(tmpbuf,"%s %c%02d%02d\n",tmpbuf,c,tz/60,tz%60);
printf(tmpbuf);//12/Dec/2011:17:36:41 +0800
}