Solution Time Format Processing scenario

Source: Internet
Author: User
Tags time in milliseconds

. Net

DateTime paramdatetime = datetime.now;//If paramgetdate==null, use the current time if (DateTime > 0) {// Converts a long type timestamp parameter to a datetime type Paramdatetime = new DateTime (1970, 1, 1). Addmilliseconds (DateTime); }

TimeSpan ts = datetime.now-new DateTime (1970, 1, 1);

Ts. TotalMilliseconds

The original Java date was added unlike. Net. Add;

Import Java.util.Date;

Date=new date ();//Take time
Calendar calendar = new GregorianCalendar ();
Calendar.settime (date);
Calendar.add (Calendar. date,1);//Increase the date by one day. Integer backwards, negative numbers move forward

   //增加1秒 calendar.add (Calendar.SECOND, 1);
Date=calendar.gettime (); This time is the result of a day pushing the date backwards.

------

Millisecond long type processing method

Using the Calendar's Settimeinmillis method, note that C.add (calendar.millisecond,int value) is not able to complete the task.

The sample code is as follows:

Calendar C = calendar.getinstance ();

C.settimeinmillis (1403931367000L);

System.out.println (C.gettime ());

------

Jquery:

New Date (). GetTime ()//Gets the current time (the number of milliseconds since 1970.1.1)
New Data (Specific point in time). GetTime ()

var timeobjectutil;/** * @title Time Tool class * @note This type of violation validation returns false * @author {[email protected]} * @date 2013-07-01 * @for Matter "2013-07-01 00:00:00", "2013-07-01" */timeobjectutil = {/** * Get current time in milliseconds */getcurrentmstime:funct        Ion () {var mydate = new Date ();    return Mydate.gettime ();        },/** * milliseconds to TIME format */longmstimeconverttodatetime:function (timestamp) {var mydate = new Date;    Return This.formatterdatetime (mydate);        },/** * Time format goes to milliseconds */datetolongmstime:function (date) {var mydate = new Date (date);    return Mydate.gettime ();                },/** * formatted date (not including time) */formatterdate:function (date) {var datetime = Date.getfullyear () + "-"//"Year" + ((Date.getmonth () + 1) > 10? (Date.getmonth () + 1): "0" + (date.getmonth () + 1)) + "-"//"month" + (d Ate.getdate () < 10?            "0" + date.getdate (): Date            . GetDate ());    return datetime;                },/** * formatted date (with time "00:00:00") */formatterdate2:function (date) {var datetime = Date.getfullyear () + "-"//"Year" + ((Date.getmonth () + 1) > 10? (Date.getmonth () + 1): "0" + (date.getmonth () + 1)) + "-"//"month" + (d Ate.getdate () < 10?        "0" + date.getdate (): Date. GetDate ()) + "" + "00:00:00";    return datetime;                },/** * formatted to date (with time) */formatterdatetime:function (date) {var datetime = Date.getfullyear () + "-"//"Year" + ((Date.getmonth () + 1) > 10? (Date.getmonth () + 1): "0" + (date.getmonth () + 1)) + "-"//"month" + (d Ate.getdate () < 10?  "0" + date.getdate (): Date. GetDate ()) + "" + (Date.gethours () < 10? "0" + date.gethours (): DATe. GetHours ()) + ":" + (Date.getminutes () < 10? " 0 "+ date.getminutes (): Date. getminutes ()) +": "+ (Date.getseconds () < 10?        "0" + date.getseconds (): Date. getseconds ());    return datetime; },/** * Time comparison {end time is greater than start time} */Comparedateendtimegtstarttime:function (StartTime, EndTime) {return (    New Date (Endtime.replace (/-/g, "/"))) > (new Date (Starttime.replace (/-/g, "/")));  },/** * Verify start time rationality {start time cannot be less than current time {X} months} */comparerightstarttime:function (month, startTime) {var now        = Formatterdayandtime (New Date ());        var SMS = new Date (Starttime.replace (/-/g, "/"));        var ems = new Date (Now.replace (/-/g, "/"));        var tdayms = Month * 30 * 24 * 60 * 60 * 1000;        var dvalue = ems-sms;        if (Dvalue > Tdayms) {return false; } return TRUe },/** * Verify start time rationality {end time cannot be less than current time {X} months} */comparerightendtime:function (month, endTime) {var now = f        Ormatterdayandtime (New Date ());        var SMS = new Date (Now.replace (/-/g, "/"));        var ems = new Date (Endtime.replace (/-/g, "/"));        var tdayms = Month * 30 * 24 * 60 * 60 * 1000;        var dvalue = Sms-ems;        if (Dvalue > Tdayms) {return false;    } return true;  },/** * Verify start time rationality {end time and start time interval cannot be greater than {X} months} */compareendtimegtstarttime:function (month, StartTime, EndTime)        {var SMS = new Date (Starttime.replace (/-/g, "/"));        var ems = new Date (Endtime.replace (/-/g, "/"));        var tdayms = Month * 30 * 24 * 60 * 60 * 1000;        var dvalue = ems-sms;        if (Dvalue > Tdayms) {return false;    } return true; },/** * Get Last days [start time and end time value, time forward] */getrecentdaysdatetime:function (day) {var daymstime = day * 2     4 * 60 * 60 * 1000;   var yesterdatsmstime = This.getcurrentmstime ()-daymstime;        var startTime = This.longmstimeconverttodatetime (yesterdatsmstime);        var pastdate = This.formatterdate2 (new Date (StartTime));        var nowdate = This.formatterdate2 (New Date ());        var obj = {starttime:pastdate, endtime:nowdate};    return obj;        },/** * gets today [start time and end time value] */gettodaydatetime:function () {var daymstime = 24 * 60 * 60 * 1000;        var tomorrowdatsmstime = this.getcurrentmstime () + daymstime;        var currenttime = This.longmstimeconverttodatetime (This.getcurrentmstime ());        var termorrowtime = This.longmstimeconverttodatetime (tomorrowdatsmstime);        var nowdate = This.formatterdate2 (new Date (currenttime));        var tomorrowdate = This.formatterdate2 (new Date (Termorrowtime));        var obj = {starttime:nowdate, endtime:tomorrowdate};    return obj; },/** * get tomorrow [start* */Gettomorrowdatetime:function () {var daymstime = 24 * 60 * 60 * 1000;        var tomorrowdatsmstime = this.getcurrentmstime () + daymstime;        var termorrowtime = This.longmstimeconverttodatetime (tomorrowdatsmstime);        var thedayaftertomorrowdatsmstime = This.getcurrentmstime () + (2 * daymstime);        var thedayaftertomorrowtime = This.longmstimeconverttodatetime (thedayaftertomorrowdatsmstime);        var pastdate = This.formatterdate2 (new Date (Termorrowtime));        var nowdate = This.formatterdate2 (new Date (Thedayaftertomorrowtime));        var obj = {starttime:pastdate, endtime:nowdate};    return obj; }};

Solution Time Format Processing scenario

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.