格式化date and time picker控件选择的日期格式
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
格式化date and time picker控件选择的日期格式
前面一片博客记录了怎么使用c脚本分别提取date and time picker控件的年、月、日,有时候我们需要提取选择的日期,还需要把这个日期按照YYYY-MM-DD这样的格式进行显示。
在wincc画面上放置一个date and time picker控件,名字修改为DT,放置一个按钮,按钮的鼠标点击事件中添加以下c脚本:
#include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
char selyear[4],seldate[10];
sprintf(selyear,"%s",GetPropChar(lpszPictureName,"DT","Year"));
if (GetPropWord(lpszPictureName,"DT","Month")>=10)
{
if (GetPropWord(lpszPictureName,"DT","Day")>=10)
sprintf(seldate,"%s-%d-%d",selyear,GetPropWord(lpszPictureName,"DT","Month"),GetPropWord(lpszPictureName,"D T","Day"));
else
sprintf(seldate,"%s-%d-d",selyear,GetPropWord(lpszPictureName,"DT","Month"),GetPropWord(lpszPictureName,"DT" ,"Day"));
}
else
{
if (GetPropWord(lpszPictureName,"DT","Day")>=10)
sprintf(seldate,"%s-d-%d",selyear,GetPropWord(lpszPictureName,"DT","Month"),GetPropWord(lpszPictureName,"DT" ,"Day"));
else
sprintf(seldate,"%s-d-d",selyear,GetPropWord(lpszPictureName,"DT","Month"),GetPropWord(lpszPictureName,"DT"," Day"));
}
MessageBox(NULL,seldate,"警告",MB_OK);
}
最终seldate变量存储的就是形如YYYY-MM-DD这种格式的日期。