TXT

CDateTimeCtrl

By Bonnie Ellis,2014-05-21 21:34
13 views 0
CDateTimeCtrl

CDateTimeCtrl inputdate控件中取得时间及保存入数据库?和设置CDateTimeCtrl控件

    显示的值

    方式,数据库中对应的字段为datetime

list.DeleteAllItems();

     CString sql,c_starttime,c_endtime;

     starttime.GetWindowText(c_starttime);

     endtime.GetWindowText(c_endtime);

     sql.Format("select

    a.stockname,a.merchandiseID,b.name,a.unitPrice,a.numbers,a.rebate,a.paymoney,c.o

    perator ,a.CancelID from tb_cancelinstock_sub a inner join tb_merchandiseinfo b on

    a.merchandiseID = b.id inner join tb_cancelinstock_main c on a.Cancelid = c.Cancelid

    and c.intime between '%s' and '%s' ",c_starttime,c_endtime);

     m_pRs->Close();

m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimist

    ic,adCmdText);

     int row = 0;

方式?,

CTime temptime;

     m_dlg2.inputdate.GetTime(temptime);

     c_intime = temptime.Format("%Y-%m-%d");

     //m_pCon->BeginTrans();

     sql.Format(" sp_cancelinstore

    '%s','%s',%10.2f,%10.2f,%10.2f,%10.2f,'%s','%s'",c_provider,c_operator,f_rebate,

    f_sumtotal,f_paymoney,f_factmoney,c_intime,"temp");

    -------------------------------------------------------

CTime time = CTime::GetCurrentTime();

     m_dlg2.inputdate.SetTime(&time);

CDateTimeCtrlCString类型转换

// 格式为:2008-01-01

CTime StrToTime(CString strTime)

    {

     int nYear,nMonth,nDay;

     sscanf(strTime,"%d-%d-%d",&nYear,&nMonth,&nDay);

     CTime Time(nYear,nMonth,nDay,0,0,0);

     return Time;

    }

    CString TimeToStr(CDateTimeCtrl& DateTime) {

     CTime Time;

     DateTime.GetTime(Time);

     return Time.Format("%Y-%m-%d"); }

void CDatesDlg::OnButton2()

     {

     // Gain a pointer to the control

     // CMonthCalCtrl* pCtrl = (CMonthCalCtrl*) GetDlgItem(IDC_MONTHCALENDAR1);

     CDateTimeCtrl* pCtrl = (CDateTimeCtrl*) GetDlgItem(IDC_DATETIMEPICKER1);

     ASSERT(pCtrl != NULL);

     // set with a CTime

     CTime timeTime(1998, 4, 3, 0, 0, 0);

     VERIFY(pCtrl->SetTime(&timeTime));

     // set with a COleDateTime object

     COleDateTime oletimeTime(1998, 4, 3, 0, 0, 0);

     VERIFY(pCtrl->SetTime(oletimeTime));

     // set using the SYSTEMTIME

     SYSTEMTIME sysTime;

     memset(&sysTime, 0, sizeof(sysTime));

     sysTime.wYear = 1998;

     sysTime.wMonth = 4;

     sysTime.wDay = 3;

     VERIFY(pCtrl->SetTime(&sysTime));

     }

数据库是sql 2000

     HelloWorld_001:

     CONVERT(data_type,expression[,style])

     SELECT CONVERT(varchar(30),getdate(),101) now

     HelloWorld_001:

     查下CONVERT的用法

     CONVERT的使用方法:

     格式:

     CONVERT(data_type,expression[,style])

     说明:

     此样式一般在时间类型(datetime,smalldatetime)与字符串类型

    (nchar,nvarchar,char,varchar)

     相互转换的时候才用到.

     例子:

     SELECT CONVERT(varchar(30),getdate(),101) now

     结果为

     now

     ---------------------------------------

     09/15/2001

     style数字在转换时间时的含义如下

--------------------------------------------------------------------------------

    -----------------

     Style(2位表示年份) | Style(4位表示年份) | 输入输出格式

--------------------------------------------------------------------------------

    -----------------

     - | 0 or 100 | mon dd yyyy hh:miAM(PM)

--------------------------------------------------------------------------------

    -----------------

     1 | 101 | mm/dd/yy

--------------------------------------------------------------------------------

    -----------------

     2 | 102 | yy-mm-dd

    -------------------------------------------------------------------------------------------------

     3 | 103 | dd/mm/yy

    -------------------------------------------------------------------------------------------------

     4 | 104 | dd-mm-yy

    -------------------------------------------------------------------------------------------------

     5 | 105 | dd-mm-yy

    -------------------------------------------------------------------------------------------------

     6 | 106 | dd mon yy

    -------------------------------------------------------------------------------------------------

     7 | 107 | mon dd,yy

    -------------------------------------------------------------------------------------------------

     8 | 108 | hh:mm:ss

    -------------------------------------------------------------------------------------------------

     - | 9 or 109 | mon dd yyyy hh:mi:ss:mmmmAM(PM)

    -------------------------------------------------------------------------------------------------

     10 | 110 | mm-dd-yy

    -------------------------------------------------------------------------------------------------

     11 | 111 | yy/mm/dd

    -------------------------------------------------------------------------------------------------

     12 | 112 | yymmdd

    -------------------------------------------------------------------------------------------------

     - | 13 or 113 | dd mon yyyy hh:mi:ss:mmm(24小时制)

--------------------------------------------------------------------------------

    -----------------

     14 | 114 | hh:mi:ss:mmm(24小时制)

--------------------------------------------------------------------------------

    -----------------

     - | 20 or 120 | yyyy-mm-dd hh:mi:ss(24小时制)

--------------------------------------------------------------------------------

    -----------------

     - | 21 or 121 | yyyy-mm-dd hh:mi:ss:mmm(24小时制)

     nanman:

     select convert(varchar(10),StartDate,120) from table

     wxno1:

     SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm");

     Date date=null;

     String dateText=null;

     <%date=dateFormat.parse((String)hm.get("time"));

     dateText=dateFormat.format(date);

     %>

     td><%=dateText%></td>

     这是我写的一段,不知道你能不能看懂

     先用dateFormat把字符串格试化成Date,再通过dateFormatformat方法格式化一下,

    就好了

     在实例化SimpleDateFormat("yyyy-MM-dd HH:mm")代表 -- 小时- 你可以直接

    写面("yyyy-MM-dd")就成了

Report this document

For any questions or suggestions please email
cust-service@docsford.com