Why the date in a programming language can be added and subtracted

Source: Internet
Author: User

I. Summary
  • The
  • date type is inside the programming language through number the
  • stored
  • Date type plus minus is actually a number plus minus

  • The date start time for most programming languages is 1970-01-01 00:00:00

two. Why is the start date for most programming languages starting from 1970-01-01 00:00:00

There are two types of interpretations that are generally available through access to information

  • Most programming languages originate from unix, and The time era of UNIX systems is 1970-01-01 00:00:00, that is the UNIX time stamp.
  • The first computers were +bit operating system, time needs to pass NumberStorage, +the potential energy represents the maximum number of2147483647. One year365the total number of seconds in a day 31536000 , the two divide68.1.so if from0000-00-00 00:00:00count the words, the computer to1901years AMonth -the day is overflowing. and choose1970years, can support to2038Library.

These two explanations, I personally more recognizedUNIXtime era of the saying that after allUNIXappeared in this year, asUNIXDevelopers need to commemorate this important day.

three. Use of UNIX of the time era Development Language 1.JAVA

Document Address: http://docs.oracle.com/javase/8/docs/api/java/util/Date.html#Date

But for Chinese developers, pass System.Out.Println (new Date (0)); , the console printing time is 1970-01-01 08:00:00, this is because China is in the East 8 district reason. There is no effect on stored values within the program.

2.Javascript

Document Address:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date

3.Python

Document Address: Https://docs.python.org/3/library/datetime.html#date-objects

4.ORACLE

Document Address: http://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/sql/TIMESTAMP.html

5.PHP

Document Address: http://php.net/manual/en/function.time.php

Four. Languages that do not use Unix timestamps1. Language based on the. Net Class Library

By default, the timestamp is represented by the int64 bit, and is accurate to 100ns and the start date point is 0001-01-01 00:00:00.000.

Document Address: Https://msdn.microsoft.com/zh-cn/library/z2xf7zzk (v=vs.110). aspx?cs-save-lang=1&cs-lang=csharp# Code-snippet-1

2.VBScript

Document Address: Https://www.microsoft.com/china/vbscript/vbstutor/vbsdatatype.htm

This start time is very strange, from the API view, the start time is from 0100-01-01 00:00:00

But judging from the code test, the start time starts from 1899-12-30 0:00:00

Five. About the Excel date system

There are two date formats in Office Excel, 1900 and 1904, that is, the start point for the date is 1900-01-01 00:00:00 and 1904-01-01 00:00:00. The general Excel default is according to 1900 date system, and think 1900 is run year, February 1900 cent according to 29 days calculate. Store in Excel The start date is 1, that is, 1900-01-01 00:00:00 the corresponding store value in Excel is 1 (days).

Why the date in a programming language can be added and subtracted

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.