1 Star 0 Fork 8

Mountain丶/Xipkpublib_Update

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
getDateTimeFormat.c 5.74 KB
一键复制 编辑 原始数据 按行查看 历史
suitianmou 提交于 2016-03-17 14:03 . ʼ1.2汾
/*******************************************************
* 公 司: 大连同方软银科技有限公司
* 程 序 名: getDateTimeFormat.c
* 程序功能: 获取渠道当前日期
* 输入参数:
* xipId 渠道标识
* 输出参数:
* object 日期
* format 日期格式
* 返 回 值:
*
* 作 者: yangF
* 开发日期: 2008/1
* 修 改 人:
* 修改日期:
*******************************************************/
#include "kernel/syspub.h"
#include "kernel/xipcmstc.h"
#include "kernel/tabincl/xip_sysdate_c.h"
void getDateTimeFormat( char* xipId , char* object, char* format,char *replyCode)
{
/*
YYYY,MM,DDD, hh,mm,ss;
format as "MM/DD/YYYY hh:mm:ss" , "MM-DD-YY", "hh-mm-ss",etc.
*/
int YearPos = -1, YearLen = 0 ;
int MonPos = -1, MonLen = 0 ;
int DayPos = -1, DayLen = 0 ;
int HourPos = -1, HourLen = 0 ;
int MinPos = -1, MinLen = 0;
int SecPos = -1, SecLen = 0;
int fmterror = 0, i;
char tradeDate[9];
char Year[5];
char Month[3];
char mDay[3];
char Hour[3];
char Minute[3];
char Second[3];
long tradeDateL = 0 ;
int HourI = 0;
int MinuteI = 0;
int SecondI = 0;
int ret = 0;
memset(tradeDate,0x00,sizeof(tradeDate));
memset(Year,0x00,sizeof(Year));
memset(Month,0x00,sizeof(Month));
memset(mDay,0x00,sizeof(mDay));
memset(Hour,0x00,sizeof(Hour));
memset(Minute,0x00,sizeof(Minute));
memset(Second,0x00,sizeof(Second));
ret = GetTradeDate(xipId,&tradeDateL,replyCode);
if(ret<0){
XIPLOG("E", "CALL getDateTimeFormat ERR = [%d]", ret);
}
sprintf(tradeDate,"%.8ld",tradeDateL);
memcpy( Year, &tradeDate[0],sizeof(Year)-1 );
Year[4]='\0';
memcpy( Month, &tradeDate[4],sizeof(Month)-1 );
Month[2]='\0';
memcpy( mDay, &tradeDate[6],sizeof(mDay)-1 );
mDay[2]='\0';
GetSysTime(&HourI, &MinuteI, &SecondI);
sprintf(Hour,"%.2d",HourI);
sprintf(Minute,"%.2d",MinuteI);
sprintf(Second,"%.2d",SecondI);
for ( i = 0; i < strlen(format); i++ ) {
switch ( format[i] ) {
case 'Y' :
if ( YearPos < 0 ) {
YearPos = i;
YearLen++;
}
else {
if ( i == ( YearPos + YearLen ) ) {
YearLen++;
}
else
fmterror = 1;
}
if ( YearLen > 4 )
fmterror = 1;
break;
case 'M' :
if ( MonPos < 0 ) {
MonPos = i;
MonLen++;
}
else {
if ( i == ( MonPos + MonLen ) ) {
MonLen++;
}
else
fmterror = 1;
}
if ( MonLen > 2 )
fmterror = 1;
break;
case 'D' :
if ( DayPos < 0 ) {
DayPos = i;
DayLen++;
}
else {
if ( i == ( DayPos+ DayLen ) ) {
DayLen++;
}
else
fmterror = 1;
}
if ( DayLen > 2 )
fmterror = 1;
break;
case 'h' :
if ( HourPos < 0 ) {
HourPos = i;
HourLen++;
}
else {
if ( i == ( HourPos + HourLen ) ){
HourLen++;
}
else
fmterror = 1;
}
if ( HourLen > 2 )
fmterror = 1;
break;
case 'm' :
if ( MinPos < 0 ) {
MinPos = i;
MinLen++;
}
else {
if ( i == ( MinPos + MinLen ) ){
MinLen++;
}
else
fmterror = 1;
}
if ( MinLen > 2 )
fmterror = 1;
break;
case 's' :
if ( SecPos < 0 ) {
SecPos = i;
SecLen++;
}
else {
if ( i == ( SecPos + SecLen ) ){
SecLen++;
}
else
fmterror = 1;
}
if ( SecLen > 2 )
fmterror = 1;
break;
default :
break;
}
if ( fmterror )
break;
}
if ( fmterror ) {
memset(object,0x00,1);
return;
}
strcpy(object,format);
if ( YearPos >= 0 ) {
if ( YearLen == 4 ) {
memcpy(object+YearPos,Year,4);
}
else if ( YearLen == 2 ) {
memcpy(object+YearPos,Year+2,2);
}
else {
memset(object,0x00,1);
return;
}
}
if ( ( MonPos >= 0 ) && ( MonLen == 2 ) )
memcpy(object+MonPos,Month,2);
if ( ( DayPos >= 0 ) && ( DayLen == 2 ) )
memcpy(object+DayPos,mDay,2);
if ( ( HourPos >= 0 ) && ( HourLen == 2 ) )
memcpy(object+HourPos,Hour,2);
if ( ( MinPos >= 0 ) && ( MinLen == 2 ) )
memcpy(object+MinPos,Minute,2);
if ( ( SecPos >= 0 ) && ( SecLen == 2 ) )
memcpy(object+SecPos,Second,2);
/*sprintf(buffer,"%.4d %.2d/%.2d/%.2d:%.2d:%.2d",clock->tm_year+1900,clock->tm_mon+1,
clock->tm_mday,clock->tm_hour,clock->tm_min,clock->tm_sec);*/
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/OnePieceMountain/Xipkpublib_Update.git
git@gitee.com:OnePieceMountain/Xipkpublib_Update.git
OnePieceMountain
Xipkpublib_Update
Xipkpublib_Update
master

搜索帮助