woshixyc 发表于 2008-9-16 16:38:14

关于获取日期时间字符串控件的问题

我用获取时间日期字符串来获取当前的时间,由于要进行时间的比较,但是如果是2008-9-9的话.按照字符串比较原则它应该大于2008-9-10,但是我要用比较值来查询数据库.请问如何使这个控件输出的时间格式是2008-9-09.

netcreature 发表于 2008-9-16 17:09:06

闲话少说,请看附件!

woshixyc 发表于 2008-9-16 17:23:39

请问版主 这个附件怎么用?那个exe文件是做什么的

netcreature 发表于 2008-9-16 17:34:28

我晕!解压后用LabWindows/CVI打开demo.cws工作空间就可以看到具体怎么实现了。那个exe文件是可执行文件,单击OK按钮,可以显示当前的格式化时间字符串。
再贴一下源代码:
#include <ansi_c.h>
#include <cvirte.h>
#include <userint.h>
#include "demo.h"
#define DATETIME_FORMATSTRING "%Y-%m-%d"
static int panelHandle;
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                     LPSTR lpszCmdLine, int nCmdShow)
{
if (InitCVIRTE (hInstance, 0, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "demo.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK OkCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
double currDateTime;
    int bufferLen;
    char *dateTimeBuffer = NULL;

switch (event)
{
case EVENT_COMMIT:
            GetCurrentDateTime (&currDateTime);
            bufferLen = FormatDateTimeString (currDateTime, DATETIME_FORMATSTRING, NULL, 0);
            dateTimeBuffer = malloc (bufferLen + 1);
            FormatDateTimeString (currDateTime, DATETIME_FORMATSTRING, dateTimeBuffer, bufferLen + 1 );
   
   SetCtrlVal(panelHandle,PANEL_STRING,dateTimeBuffer);
   break;
case EVENT_GOT_FOCUS:
   break;
}
return 0;
}
int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
   QuitUserInterface (0);
   break;
case EVENT_GOT_FOCUS:
   break;
}
return 0;
}
页: [1]
查看完整版本: 关于获取日期时间字符串控件的问题