DATE到字符串 [英] DATE to string

查看:81
本文介绍了DATE到字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个非MFC C ++应用程序(第三方数据库系统的插件)。

该应用程序旨在同步MS Outlook和数据库之间的数据

系统。我正在使用智能指针进行开发,这很好并且

sysnchronisation来回正常工作。我的问题是
有DATE类型(使用8字节浮点数实现
数。天数以整数增量表示,从30开始/>
1899年12月,午夜为时间零。小时值表示为数字小数部分的绝对值

。)。 MS Outlook使用

DATE类型用于电子邮件日期,约会日期等,例如

spMailItem-> GetReceivedTime()我需要将其转换为

可读格式,例如25/12/2006 10:29:00我似乎无法得到这个

的工作。我还需要走另一条路(字符串到DATE)。任何人都可以提供一个

简单的代码示例为我这样做,因为我到处寻找并且不能

找到一个有效的非MFC示例。

谢谢。

I am writing a NON MFC C++ application (Plug-in for a 3rd party DB system).
The application is designed to synchronise data between MS Outlook and the DB
system. I am using smart pointers for the development which is fine and
sysnchronisation back and forth is working as expected. The problem I am
having is with the DATE type (implemented using an 8-byte floating-point
number. Days are represented by whole number increments starting with 30
December 1899, midnight as time zero. Hour values are expressed as the
absolute value of the fractional part of the number. ). MS Outlook uses the
DATE type for e-mail dates, appointment dates etc e.g
spMailItem->GetReceivedTime() which I need to convert to a string in a
readable format e.g "25/12/2006 10:29:00" I just cant seem to get this to
work. I also need to go the other way (string to DATE). Can anyone provide a
simple code example to do this for me as I have looked everywhere and cannot
find a NON MFC example that works.

Thanks.

推荐答案

嗨jwf!
Hi jwf!

我的问题是
有DATE类型(使用8字节浮点实现

number。天数以整数增量表示,以18

开始,1899年12月,午夜为零时。小时值表示为小数部分的绝对值

数量。)
The problem I am
having is with the DATE type (implemented using an 8-byte floating-point
number. Days are represented by whole number increments starting with 30
December 1899, midnight as time zero. Hour values are expressed as the
absolute value of the fractional part of the number. ).



首先将DATE转换为SYSTEMTIME:

- VariantTimeToSystemTime

然后你可以把它转换成你想要的任何字符串。


另一种方式:

SystemTimeToVariantTime


-

问候

Jochen


我关于Win32和.NET的博客
http://blog.kalmbachnet.de/




" jwf" < jw*@newsgroups.nospamwrote in message

news:00 ***************************** ***** @ microsof t.com ...

"jwf" <jw*@newsgroups.nospamwrote in message
news:00**********************************@microsof t.com...

>我正在编写一个非MFC C ++应用程序(第三方数据库系统的插件) 。

该应用程序旨在同步MS Outlook和

DB

系统之间的数据。我正在使用智能指针进行开发,这很好并且

sysnchronisation来回正常工作。我的问题是
有DATE类型(使用8字节浮点数实现
数。天数以整数增量表示,从30开始/>
1899年12月,午夜为时间零。小时值表示为数字小数部分的绝对值

。)。 MS Outlook使用



DATE类型的电子邮件日期,约会日期等,例如

spMailItem-> GetReceivedTime()我需要的转换为

可读格式的字符串,例如25/12/2006 10:29:00我似乎无法得到这个

的工作。我还需要走另一条路(字符串到DATE)。任何人都可以提供一个

简单的代码示例来为我这样做,因为我到处寻找并且

不能

找到一个有效的NON MFC示例。
>I am writing a NON MFC C++ application (Plug-in for a 3rd party DB system).
The application is designed to synchronise data between MS Outlook and the
DB
system. I am using smart pointers for the development which is fine and
sysnchronisation back and forth is working as expected. The problem I am
having is with the DATE type (implemented using an 8-byte floating-point
number. Days are represented by whole number increments starting with 30
December 1899, midnight as time zero. Hour values are expressed as the
absolute value of the fractional part of the number. ). MS Outlook uses
the
DATE type for e-mail dates, appointment dates etc e.g
spMailItem->GetReceivedTime() which I need to convert to a string in a
readable format e.g "25/12/2006 10:29:00" I just cant seem to get this to
work. I also need to go the other way (string to DATE). Can anyone
provide a
simple code example to do this for me as I have looked everywhere and
cannot
find a NON MFC example that works.



这是一个简单的:)

来自Oleaut32.dll的
VarFormatDateTime()

它需要VARIANT *但变体是vt = VT_DATE;只需将日期

值复制到日期成员。


其次,如果你想传递一个掩码,你会使用VarFormat().. 。

VARIANT v = {0};

v.vt = VT_DATE;

v.date = yourDate;

CComBSTR thFmt;

HRESULT hr = VarFormatDateTime(& v,0,0& thFmt);


但我从不使用此功能,我使用VarFormat()的组合并使用

GetLocaleInfoW来获取日期/时间掩码。那个面具传递给VarFormat

然后你就去了!

This is a simple one :)

VarFormatDateTime() from Oleaut32.dll
It takes a VARIANT* but the variant is vt = VT_DATE; just copy your date
value to the date member.

Secondly, if you want to pass a mask, you''d take VarFormat()...
VARIANT v={0};
v.vt = VT_DATE;
v.date = yourDate;
CComBSTR thFmt;
HRESULT hr = VarFormatDateTime(&v, 0, 0, &thFmt);

But I never use this function, I use a combination of VarFormat() and use
GetLocaleInfoW to get the date / time mask. That mask is passed to VarFormat
and there you go!


谢谢。
Thanks.




" Egbert Nierop(IIS的MVP)" <例如*********** @ nospam.invalidwrote在

消息新闻:em ************* @ TK2MSFTNGP03.phx.gbl ...


当然,你应该把它转换成一个函数。


FYI


LCID lcid = GetThreadLocale();

SYSTEMTIME st = {0};

CComBSTR fmt;

int lenReq = GetLocaleInfoW(lcid,LOCALE_SSHORTDATE ,NULL,0);

if(lenReq 0)

{

fmt.SetLength(lenReq - 1);

GetLocaleInfoW(lcid,LOCALE_SSHORTDATE,fmt,lenReq);

}


lenReq = GetLocaleInfoW(lcid,LOCALE_STIMEFORMAT,NULL,0);

if(lenReq 0)

{

text.SetLength(lenReq - 1);

GetLocaleInfoW(lcid,LOCALE_STIMEFORMAT ,text,lenReq);

fmt.Append(L''');

fmt + = text; //现在fmt包含例如mm-dd-yyyy hh:mm

}


VARIANT v = {0};

v.vt = VT_DATE;

v.date = [yourdatehere]

HRESULT hr = VarFormatDateTime(& v,0,0,& fmt);


"Egbert Nierop (MVP for IIS)" <eg***********@nospam.invalidwrote in
message news:em*************@TK2MSFTNGP03.phx.gbl...

Of course, you should convert this into a function.

FYI

LCID lcid = GetThreadLocale();
SYSTEMTIME st={0};
CComBSTR fmt;
int lenReq = GetLocaleInfoW(lcid, LOCALE_SSHORTDATE, NULL, 0);
if (lenReq 0)
{
fmt.SetLength(lenReq - 1);
GetLocaleInfoW(lcid, LOCALE_SSHORTDATE, fmt, lenReq);
}

lenReq = GetLocaleInfoW(lcid, LOCALE_STIMEFORMAT, NULL, 0);
if (lenReq 0)
{
text.SetLength(lenReq - 1);
GetLocaleInfoW(lcid, LOCALE_STIMEFORMAT, text, lenReq);
fmt.Append(L'' '');
fmt += text; //now fmt contains eg mm-dd-yyyy hh:mm
}

VARIANT v={0};
v.vt = VT_DATE;
v.date = [yourdatehere]
HRESULT hr = VarFormatDateTime(&v, 0, 0, &fmt);


这篇关于DATE到字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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