Пример #1
0
        public static TdrError.ErrorType tdrDateTime2Str(ref TdrVisualBuf buf, UInt64 datetime)
        {
            TdrError.ErrorType ret         = TdrError.ErrorType.TDR_NO_ERROR;
            TdrDateTime        tdrDateTime = new TdrDateTime();

            ret = tdrDateTime.parse(datetime);
            if (TdrError.ErrorType.TDR_NO_ERROR == ret)
            {
                ret = buf.sprintf("{0:d4}-{1:d2}-{2:d2} {3:d2}:{4:d2}:{5:d2}",
                                  tdrDateTime.tdrDate.nYear, tdrDateTime.tdrDate.bMon, tdrDateTime.tdrDate.bDay,
                                  tdrDateTime.tdrTime.nHour, tdrDateTime.tdrTime.bMin, tdrDateTime.tdrTime.bSec);
            }
            else
            {
#if (DEBUG)
                StackTrace st = new StackTrace(true);
                for (int i = 0; i < st.FrameCount; i++)
                {
                    if (null != st.GetFrame(i).GetFileName())
                    {
                        Console.WriteLine(st.GetFrame(i).ToString());
                    }
                }
#endif
                ret = TdrError.ErrorType.TDR_ERR_INVALID_TDRDATETIME_VALUE;
            }

            return(ret);
        }
Пример #2
0
        public static TdrError.ErrorType str2TdrDateTime(out UInt64 datetime, string strDateTime)
        {
            TdrError.ErrorType ret = TdrError.ErrorType.TDR_NO_ERROR;
            DateTime           dt;
            TdrDateTime        tdrDateTime = new TdrDateTime();

            if (DateTime.TryParse(strDateTime, out dt))
            {
                tdrDateTime.tdrDate.nYear = (short)dt.Year;
                tdrDateTime.tdrDate.bMon  = (byte)dt.Month;
                tdrDateTime.tdrDate.bDay  = (byte)dt.Day;

                tdrDateTime.tdrTime.nHour = (short)dt.TimeOfDay.Hours;
                tdrDateTime.tdrTime.bMin  = (byte)dt.TimeOfDay.Minutes;
                tdrDateTime.tdrTime.bSec  = (byte)dt.TimeOfDay.Seconds;

                tdrDateTime.toDateTime(out datetime);
            }
            else
            {
#if (DEBUG)
                StackTrace st = new StackTrace(true);
                for (int i = 0; i < st.FrameCount; i++)
                {
                    if (null != st.GetFrame(i).GetFileName())
                    {
                        Console.WriteLine(st.GetFrame(i).ToString());
                    }
                }
#endif
                datetime = 0;
                ret      = TdrError.ErrorType.TDR_ERR_INVALID_TDRDATETIME_VALUE;
            }

            return(ret);
        }