iOS is often used to show code snippets a few hours ago/days ago/months ago/years ago2015-03-13 10:09copyright Notice: Please pay attention to personal blog: http://www.henishuo.com/print?
/**
* Retain a formated string with a real date string
*
* @param datestring a real date string, which can be converted to a NSDate object
*
* @return A string t
Package Com.zuidaima;import Java.text.parseexception;import Java.text.simpledateformat;import java.util.Date; public class Relativedateformat {private static final long One_minute = 60000L; Private static final long one_hour = 3600000L; Private static final long one_day = 86400000L; Private static final long One_week = 604800000L; private static final String One_second_ago = "seconds ago"; private static final String One_minute_ago = "Minutes ago"; private static final Strin
Tags: style blog ar color using SP on data divDefinition and usageDATEADD() function to add or subtract a specified time interval from a date.GrammarDATEADD(DatePart, Number, date)The date parameter is a valid day expression. Numberis the number of intervals you want to add; for future time, this number is positive, and for the past time, this number is negative.DatePartThe parameter can be the following value:DatePartAbbreviationYear yy, yyyyQuarterly QQ, Qmonth mm, MThe day of the year dy, yDa
A few seconds ago, a few minutes ago, a few hours ago, a few days ago, a few months ago, a few years ago, java Implementation
Package com. zuidaima; import java. text. parseException; import java. text. simpleDateFormat; import java. util. date; public class RelativeDateFormat {private static final long ONE_MINUTE = 60000L; private static final long ONE_HOUR = 36
The first method, implemented using the PHP class library
/** * Function: Calculates how many years, how many months, and how many days are two dates * param string $date 1[format: 2011-11-5] * param string $date 2[format such as: 2012-12-01] * return array array (' Year ', ' Month ', ' Day '); */function diffdate ($date 1, $date 2) {$datetime 1 = new \datet
PHP gets the year, month, day, hour, minute, second of the specified time period, PHP gets
Core code:
Class Utils {/** * format mysql DateTime (yyyy-mm-dd hh:mm:ss) converts the data format found in MySQL into time seconds * @param string $datetime */pu Blic function Fmdatetime ($datetime) {$year = substr ($datetime, 0,4); $month = substr ($datetime, 5,2); $day = substr ($datetime, 8,2); $hour = substr ($datetime, 11,2); $min = substr ($datetime, 14,2); $sec = substr ($datetime, 17,2); Re
: This article describes how many years, months, and days are separated by two dates in php. For more information about PHP tutorials, see. The first method is implemented using the PHP class library.
/*** Function: calculate the number of years, months, and
Original: Java a few seconds ago, a few minutes ago, a few hours ago, a few days ago, a few months ago, a few years ago realizedSource code: Http://www.zuidaima.com/share/1562038902000640.htmPrevious code shared by cattle people:Java implementation a few minutes ago, a few hours ago, a few days before the codeA bit com
nsstring*distancetime=[selfreturnfromthetimeoftoday:@ " 2016-09-2901:45:10 "]; #pragma mark default one minute has 60 seconds, 60 minutes an hour 24 hours a day, 7 days a week, one months 30 days, 12 months a year Do not consider other such as common year February 28 days,
Value:Hour:0 to 23Minute:0 to 59second:0 to 59.999999999eg
Interval ' 4 5:12:10.222 ' Day to second (3) means: 4 days 5 hours 12 minutes 10.222 seconds
Interval ' 4 5:12 ' day to Minute said: 4 days 5 hours 12 minutes
Interval ' 5 ' Day (3) to hour means: 400 days 5 hours, 400 is 3 for precision, so "day (3)", note the default value is 2.
Interval
We often see in the comments how many days ago, how many hours ago.The principle of implementation: now time-past time to get the difference between the comparisonBelow I define a helper class, you can directly reference, parameter is the time difference, note that the time difference type is a timespan type, not a DateTime type OH ~TimeHelper.csusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceTime Test {/// /
Obtain time information in NSDate, in years, months, weeks, days, hours, minutes, seconds, and milliseconds:
Note: The first method cannot obtain information in milliseconds, and the second method is used to obtain information in milliseconds.
[Cpp] NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];NSDate * now;NSDateCom
PHP calculates the difference between two time periods (in seconds, days, months, and years). example code:
The code is as follows:
$ Yourdate = "2012-10-20 ";
$ Yourdate_unix = strtotime ($ yourdate );
Echo (date ("Y", $ yourdate_unix)-date ("Y") * 12 + (date ("m", $ yourdate_unix) -date ("m "));
Example 1
The code is as follows:
/*
* Calculate the
PHP calculates the time interval of n days, weeks, months, and years.
Date_default_timezone_set ('prc'); // Set the time zone
$ Date1 = strtotime ('1970-01-01 '); // converts a date to a timestamp.
$ Date2 = time (); // Obtain the timestamp of the current time
$ Nowtime = strftime ("% Y-% m-% d", $ date2); //
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.