Hey everyone! Welcome to another of my blogs. Today, we will talk about timedate formats. So, why don't people just use the same timeDate format for every country, village, city, etc.? Simply, because people are used to it. So, what does timeDate format consist off? Well for both date and time, the order of month, day, year or hour minute second matters, and the for time matters if the time is 12-hour or 24-hours, and for date it also matters if the month is spelled, or as a number(January would be 1, or the other way around). And what mainly mattered, was the symbols that splitted these 3 values appart. Because programmers were already confused with the timezones, adding even more complexity would make it too hard to solve this in plausible amount of time, and thats why dateTime formats, and dateTime format strings were invented. You simply put your format string in, and execute the function on it, and done! However, they came with some limitations. Even tho this allowed you setting custom characters and everything inbetween the date, you couldnt still get the am/pm. But that was added later and now, its complete! So lets check it out, shall we? So, this is an example for date formats: dd/MM/yyyy or MM.dd/yyyy etc. And here are some for time: hh:mm tt HH:mm:ss Why is the HH and MM capitalized? The HH can be capitalized to let the formatter know to use 24-hour format, and the tt will be replaced with AM or PM. As for the MM and mm, thats because mm is for minutes, while MM is for months. Why would they need to be something different, when they are formats for something else, date and time, right? Well, not exactly. Sometimes, you want to define both date and time in the same string, with format string like so: "dd/MM/yyyy HH:mm:ss". Now, you may think, how could we efficiently store all this time in some portable, universal format? Good question, and theres a perfect answer for you, its unix time. What is unix time? Unix time is simply a 32-bit(or 64-bit) integer, storing data in the format of how many seconds have happened since first january, 1970(1/1/1970, 12:00) in format of (dd/MM/yyyy, HH:mm). This time is perfect, because it doesn't care about what holidays were, what year it was, etc. And this all can be stored in just 4 bytes. Have you ever been wondering why, when you take your CMOS baterry out, the time is exactly 1/1/1970? Its because the bios lost all data in its register, and it turned into zero. Everyone has also been talking about the year 2038, or Y2K38 for short(or more like long). So, what will happen in this year exactly? Well, the amount of seconds since 1970 will reach 2147483648(2^31), aka the time will reset to 1901 on all systems that are still using 32bit architecture of any kind. Why 2^31 tho, and not 2^32? And why 1901, and now 1970? Why is the amount of seconds a signed integer? Well believe it or not, but it actually server a good purpose, or atleast it did. Lets do some math. 2^31 is 2147483648, now how many years is that? Well, hour has 3600 seconds, and month has 24*30 hours, so there are 720(or 744 if the month has 31days, but we will ignore that for now) hours in a month. Now, 3600 * 720 = 2592000seconds/month. Now, thats *12 per year, so thats ~31104000seconds/year. And now, 2^31 / 31104000 = 69years, neat. This meant that it was planned for this time format to actually be able to go back in time too, and to be exact to the year 1901, which is realistically the oldest anyone could ever thing of, right historians? ;D Thats why unix format was established this way. So, -2147483648unix seconds is somewhere in the year 1901, but, why would it go to negatives? Well, its because of the 2's complement. What does that mean? Well in simple terms, to extend by the maximum negative capacity by one, all binary values in negatives are flipper, therefore if there was 8bit -1, it would look like this: 0b11111110. If it was -128(-0x80) it would be 0b10000000(only the sign bit is 1). All this to extend the capacity but one, but oh-well. This means the number will turn from 0x0FFFFFFF to 0x100000000, aka -2bilion..., remember, the computer is just blindly adding one, and especially in binary, digit overflow is very common. In fact it will happen on any random bit by 50%, because if the 0b001 + 1 = 0b010, etc., just flip 1 and its already turn to negatives. How do we solve all this? Thats right, we extend the number to 64bits. And due to exponentials, this timestamp will be not 70years, not 71years, but until the heat death of the solar system, and beyond, so we will not be needing 96 or 128bit one anytime soon. Whats the current unix time? Well, lets calculate this. As this blog is named 2024-05-28., you can propably predict when it was created. But wait, why did I got for yyyy-MM-dd? Well, intially I used indexes for these blogs(0, 1, 2, etc.), then I used dd-MM-yyyy. The problem was the ftp server wasnt liking it, so I had to do it this way, so it wouldn't order by day. Back to the question tho, what is the current unix second? Lets do the math! Its 2024, and 2024 - 1970 = 54, so 54years. Its May, so 5months 5-1 = 4, so 4months Its 28th, so 28 - 1 = 27, so 27days So, 54 * 31104000 + 4 * 2592000 + 27 * 3600 * 24 = 1679616000 + 10368000 + 2332800 = 1692316800. Is that correct? Lets check some online website about it. The actual time was 1716925188 which is preety close. I not only not included the current time, but also the fact that... yes timezones and years and all the stuff mentioned above. Thats why programmers like unix seconds. Well, thats about it for today, I, out.