Home > Net >  To PC time (year, month, day,, points, SEC) written by DateTime convert date type variables, find ti
To PC time (year, month, day,, points, SEC) written by DateTime convert date type variables, find ti

Time:09-21


Microcontroller to PC time (year, month, day,, points, SEC), PC via a DateTime type conversion to date variables to the database, other times, database storage time is correct, but at 00:10 08:00 -- - this time, there is something wrong with the database storage time, the problem is as follows:

1, the single chip microcomputer is uploaded on September 21, 2020, 0 0 seconds at
Database is stored on September 20, 2020 0 0 PM seconds,
2, the microcontroller is uploaded on September 21, 2020, 8 0 0 seconds
Database is stored on September 20, 2020 at 8 0 0 seconds,
3, the single chip microcomputer to upload other period of time, database storage OK


4, single chip microcomputer to upload time stored in the byte buffer, written by the following code into a DateTime type variable database:

 private DateTime BytesToDateTime (byte [] bytes) 
{
If (bytes!=null & amp; & Bytes. The Length & gt;
=6){
Int year=2000 + (int) bytes [0].
Int the month=(int) bytes [1].
Int day=(int) bytes [2].
Int hour=(int) bytes [3].
Int minute=(int) bytes [4].
Int second=(int) bytes [5].
DateTime dt=new DateTime (year, month, day, hour, minute, second);
Return dt.
}
The else
{
Return new DateTime ();
}
}



Excuse me: what reason? Did not consider Beijing east eight area?

CodePudding user response:



CodePudding user response:

I can only say that China's time zone in east eight area

You had several way, so we can't answer, where you have any question

CodePudding user response:

Bytes [2] is wrong, mostly single-chip microcomputer by value is wrong,

CodePudding user response:

The key is to other periods of time is right, only the morning 0:10 - between 8:00 in the right time (note: every 10 minutes I upload a time),

Morning 0:10 - between 8:00 in the right time, just wrong day [date], year, month, hours, minutes and seconds are all right,

For example: single chip microcomputer to upload time for the 2020-09-21 00:10:00
Should be recorded as the 2020-09-21 00:10:00
The actual record for the 2020-09-20 00:10:00 - & gt; Just [date] are recorded as of yesterday's date, other right
  •  Tags:  
  • C#