In many cases, we need to get the day of the week. Many people like to set the day of the week in the clock setting. In fact, there is no need to be so troublesome. We only need to get the date to calculate the day of the week at any time.
The week is calculated with a fixed period of 7 days. Therefore, as long as the date is obtained, the specific day can be obtained by calculating 7 as a period. The specific function is as follows:
/****************************************************** *************************************
* FunctionName : GetWeek()
* Description: Get the week by date
* EntryParameter : year, month, day - date
* ReturnValue: Returns the week
*************************************************** ************************************/
U8 GetWeek(U8 year, U8 month, U8 day)
{
U8 i, y, m, d, weekDay;
U16ti = 2000;
U32 days = 0;
y = (year >> 4) * 10 + (year & 0x0F);
m = (month >> 4) * 10 + (month & 0x0F);
d = (day >> 4) * 10 + (day & 0x0F);
for (i = 0; i
Reference address:Calculate the day of the week from the date
{
if ((ti % 4) == 0 && (ti % 100) != 0 || (ti % 400) == 0)
{
days += 366;
}
else
{
days += 365;
}
ti++;
}
for (i = 1; i
{
switch (i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
days += 31;
break;
}
case 2:
{
ti = 2000 + y;
if ((ti % 4) == 0 && (ti % 100) != 0 || (ti % 400) == 0)
{
days += 29;
}
else
{
days += 28;
}
break;
}
case 4:
case 6:
case 9:
case 11:
{
days += 30;
break;
}
}
}
days += d;
weekDay = (days % 7) + 5;
weekDay %= 7;
return weekDay;
}
Previous article:Implementation of single chip microcomputer power on and off
Next article:Serial port data processing of single chip microcomputer
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
Guess you like
- How does this circuit achieve precise voltage regulation?
- MicropyCli - Micropython project management automation
- Doping of semiconductors from the perspective of energy levels
- EEWORLD University - HDMI 2.1 Design and Testing Update
- Design of breathing light based on FPGA
- Classification, functions and effects of interface circuits
- 【GD32307E-START】+ driver display of digital tube display module
- ST Live Broadcast on March 19: Introduction to SensorTile.box, Bone Vibration Sensor, and Machine Learning Sensor Development
- Application of Operational Amplifier in Voltage Comparator
- Error message when importing bsp project into CCS6