Time (converted from timestamp to timestamp)

Source: Internet
Author: User

Time (converted from timestamp to timestamp)

Public class Date_U {/*** drop this method and enter the time to be converted, for example, ("June 14, 2014 seconds ") return timestamp ** @ param time * @ return */public String data (String time) {SimpleDateFormat sdr = new SimpleDateFormat ("MM minute ss seconds at HH on mm dd, yyyy", Locale. CHINA); Date date; String times = null; try {date = sdr. parse (time); long l = date. getTime (); String stf = String. valueOf (l); times = stf. substring (0, 10); Log. d ("-- 444444 ---", times);} catch (ParseException e) {e. printStackTrace ();} return times;}/*** drop this method and enter the time to be converted, for example ("2014-06-14-16-09-00 ") return timestamp ** @ param time * @ return */public String dataOne (String time) {SimpleDateFormat sdr = new SimpleDateFormat ("yyyy-MM-dd-HH-mm-ss", Locale. CHINA); Date date; String times = null; try {date = sdr. parse (time); long l = date. getTime (); String stf = String. valueOf (l); times = stf. substring (0, 10); Log. d ("-- 444444 ---", times);} catch (ParseException e) {e. printStackTrace ();} return times;} public static String getTimestamp (String time, String type) {SimpleDateFormat sdr = new SimpleDateFormat (type, Locale. CHINA); Date date; String times = null; try {date = sdr. parse (time); long l = date. getTime (); String stf = String. valueOf (l); times = stf. substring (0, 10); Log. d ("-- 444444 ---", times);} catch (ParseException e) {e. printStackTrace ();} return times;}/*** call this method to enter the timestamp to be converted, for example, (1402733340) output ("June 14, 2014 ") ** @ param time * @ return */public String times (String time) {SimpleDateFormat sdr = new SimpleDateFormat ("MM, dd, yyyy, HH, mm, ss, SEC "); @ SuppressWarnings ("unused") long Kp = Long. valueOf (time); int I = Integer. parseInt (time); String times = sdr. format (new Date (I * 1000L); return times;}/*** call this method to enter the timestamp to be converted, for example (1402733340) output ("June 14, 2014") ** @ param time * @ return */public String timet (String time) {SimpleDateFormat sdr = new SimpleDateFormat ("MM minute, HH, mm dd, yyyy"); @ SuppressWarnings ("unused") long lcc = Long. valueOf (time); int I = Integer. parseInt (time); String times = sdr. format (new Date (I * 1000L); return times ;}// call this method to enter the timestamp to be converted, for example (1402733340) output ("June 14, 2014 seconds") public static String times (long timeStamp) {SimpleDateFormat sdr = new SimpleDateFormat ("MM dd # HH: mm "); return sdr. format (new Date (timeStamp )). replaceAll ("#", getWeek (timeStamp);} private static String getWeek (long timeStamp) {int mydate = 0; String week = null; Calendar cd = Calendar. getInstance (); cd. setTime (new Date (timeStamp); mydate = cd. get (Calendar. DAY_OF_WEEK); // get the specified date to the day of the week if (mydate = 1) {week = "Sunday";} else if (mydate = 2) {week = "Monday";} else if (mydate = 3) {week = "Tuesday";} else if (mydate = 4) {week = "Wednesday ";} else if (mydate = 5) {week = "Thursday";} else if (mydate = 6) {week = "Friday";} else if (mydate = 7) {week = "Saturday" ;}return week ;}// use a delimiter to divide the time into time arrays/*** call this method to enter the timestamp to be converted, for example (1402733340) output ("2014-06-14-16-09-00") ** @ param time * @ return */public String timesOne (String time) {SimpleDateFormat sdr = new SimpleDateFormat ("yyyy-MM-dd-HH-mm-ss"); @ SuppressWarnings ("unused") long SVC = Long. valueOf (time); int I = Integer. parseInt (time); String times = sdr. format (new Date (I * 1000L); return times ;} /*** divide the time into time Arrays Using delimiters ** @ param time * @ return */public static String [] timestamp (String time) {SimpleDateFormat sdr = new SimpleDateFormat ("MM minute ss seconds at HH on mm dd, yyyy"); @ SuppressWarnings ("unused") long MHD = Long. valueOf (time); int I = Integer. parseInt (time); String times = sdr. format (new Date (I * 1000L); String [] fenge = times. split ("[year, month, day, hour, minute, and second]"); return fenge;}/*** format the time according to the passed type ** @ param str * @ param type * For example: yy-MM-dd * @ return */public static String getDateTimeByMillisecond (String str, String type) {Date date Date = new Date (Long. valueOf (str); SimpleDateFormat format = new SimpleDateFormat (type); String time = format. format (date); return time;}/*** delimiter divides time into time arrays ** @ param time * @ return */public String [] division (String time) {String [] fenge = time. split ("[year, month, day, hour, minute, second]"); return fenge ;} /*** enter the timestamp to change the week ** @ param time * @ return */public static String changeweek (String time) {SimpleDateFormat sdr = new SimpleDateFormat ("MM minute ss seconds at HH on mm dd, yyyy"); long Kp = Long. valueOf (time); int I = Integer. parseInt (time); String times = sdr. format (new Date (I * 1000L); Date date = null; int mydate = 0; String week = null; try {date = sdr. parse (times); Calendar cd = Calendar. getInstance (); cd. setTime (date); mydate = cd. get (Calendar. DAY_OF_WEEK); // get the specified date to the day of the week} catch (ParseException e) {// TODO Auto-generated catch blocke. printStackTrace ();} if (mydate = 1) {week = "Sunday";} else if (mydate = 2) {week = "Monday ";} else if (mydate = 3) {week = "Tuesday";} else if (mydate = 4) {week = "Wednesday";} else if (mydate = 5) {week = "Thursday";} else if (mydate = 6) {week = "Friday";} else if (mydate = 7) {week = "Saturday ";} return week;}/*** get the date and week, for example, 2014-11-13 Monday ** @ param time * @ param type * @ return */public static String getDateAndWeek (String time, string type) {return getDateTimeByMillisecond (time + "000", type) + "" + changeweekOne (time );} /*** enter the timestamp to change the week ** @ param time * @ return */public static String changeweekOne (String time) {SimpleDateFormat sdr = new SimpleDateFormat ("yyyy-MM-dd-HH-mm-ss"); long Kp = Long. valueOf (time); int I = Integer. parseInt (time); String times = sdr. format (new Date (I * 1000L); Date date = null; int mydate = 0; String week = null; try {date = sdr. parse (times); Calendar cd = Calendar. getInstance (); cd. setTime (date); mydate = cd. get (Calendar. DAY_OF_WEEK); // get the specified date to the day of the week} catch (ParseException e) {// TODO Auto-generated catch blocke. printStackTrace ();} if (mydate = 1) {week = "Sunday";} else if (mydate = 2) {week = "Monday ";} else if (mydate = 3) {week = "Tuesday";} else if (mydate = 4) {week = "Wednesday";} else if (mydate = 5) {week = "Thursday";} else if (mydate = 6) {week = "Friday";} else if (mydate = 7) {week = "Saturday ";} return week;}/*** get the current time ** @ return */public static String getCurrentTime () {SimpleDateFormat sdf = new SimpleDateFormat ("MM Minute At HH on mm dd, yyyy"); return sdf. format (new java. util. date ();}/*** input Date (for example, June 14, 2014 seconds) Return (number of weeks) ** @ param time * @ return */public String week (String time) {Date date Date = null; simpleDateFormat sdr = new SimpleDateFormat ("MM minute ss seconds at HH on mm dd, yyyy"); int mydate = 0; String week = null; try {date = sdr. parse (time); Calendar cd = Calendar. getInstance (); cd. setTime (date); mydate = cd. get (Calendar. DAY_OF_WEEK); // get the specified date to the day of the week} catch (ParseException e) {// TODO Auto-generated catch blocke. printStackTrace ();} if (mydate = 1) {week = "Sunday";} else if (mydate = 2) {week = "Monday ";} else if (mydate = 3) {week = "Tuesday";} else if (mydate = 4) {week = "Wednesday";} else if (mydate = 5) {week = "Thursday";} else if (mydate = 6) {week = "Friday";} else if (mydate = 7) {week = "Saturday ";} return week;}/*** input date (for example, 2014-06-14-16-09-00) return (number of weeks) ** @ param time * @ return */public String weekOne (String time) {Date date = null; simpleDateFormat sdr = new SimpleDateFormat ("yyyy-MM-dd-HH-mm-ss"); int mydate = 0; String week = null; try {date = sdr. parse (time); Calendar cd = Calendar. getInstance (); cd. setTime (date); mydate = cd. get (Calendar. DAY_OF_WEEK); // get the specified date to the day of the week} catch (ParseException e) {// TODO Auto-generated catch blocke. printStackTrace ();} if (mydate = 1) {week = "Sunday";} else if (mydate = 2) {week = "Monday ";} else if (mydate = 3) {week = "Tuesday";} else if (mydate = 4) {week = "Wednesday";} else if (mydate = 5) {week = "Thursday";} else if (mydate = 6) {week = "Friday";} else if (mydate = 7) {week = "Saturday ";} return week ;}


Convert the php timestamp to time

Time ();
Returns the current time, but returns an integer.

You can format it.
Date ("Y-m-d H: I: s", time ());
In this way, the connections are displayed in minutes.
Date ("Y-m-d", time (); year, month, and day only

For details, see hi.baidu.com/..9.html.

SQL statements also have time functions. You can check them here.
User.qzone.qq.com/120868600/blog/1238421401

In js, convert a date to a timestamp, for example, 2013-08-30 to a timestamp.

I have encountered a timestamp issue before. In order not to be despised by everyone, let's talk about the concept first.

I don't know how to define the specific timestamp, but Baidu encyclopedia says, "The timestamp is the total number of seconds from January 1, January 1, 1970 (00:00:00 GMT) to the current time ".

According to this definition, there is a similar function in the programming language, getTime (), but this function returns the total number of milliseconds from January 1, January 1, 1970 to the current time, rather than the total number of seconds.

In js, converting a character to the Date type is not difficult:
Var str = '2017-08-30 '; // Date string

Str = str. replace (/-/g, '/'); // replace-with/, because the following constructor only supports date strings separated /.

Var date = new Date (str); // construct a date type data with the value of the input string

In the preceding section, the new Date (str) constructs a Date. The str parameter must provide at least three parts: year, month, and day, that is, the string in the form of "2013/03/08". It cannot be "2013/03 ", otherwise, a NaN is obtained. The constructed time is: 00:00:00. You can also specify the hour, minute, and second, but not the hour, for example, 2013/03/08 17. This parameter also produces a NaN. The parameter can be "17:20:05" or "" to get the correct time. If the number of seconds is not given, the default value is 0.

In this case, we get the date data. To get the so-called timestamp above, we can do this:
Var time = date. getTime ();
In this way, we get a value that represents the number of milliseconds from 00:00:00 on the first day of the month to the date. If we divide this number by 1000, we get the number of seconds. We also continue to divide it by 60 to get the minute, divide by 60 to get the hour and so on.

Tip: using this getTime () function, you can get the number of milliseconds of two dates and convert them into seconds, minutes, hours, or even days to compare the difference between the two dates.

Related Article

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.