a y-----has12months ago怎填

a y-----has12months怎填_百度作业帮
拍照搜题,秒出答案
a y-----has12months怎填
a y-----has12months怎填
答案yearA year has 12 months.一年有12个月.Keyboard Shortcuts?
Next menu item
Previous menu item
Previous man page
Next man page
Scroll to bottom
Scroll to top
Goto homepage
Goto search(current page)
Focus search box
Change language:
Brazilian Portuguese
Chinese (Simplified)
The function expects to be given a string containing an English date format
and will try to parse that format into a Unix timestamp (the number of
seconds since January 1 :00 UTC), relative to the timestamp given
in now, or the current time if
now is not supplied.
Each parameter of this function uses the default time zone unless a
time zone is specified in that parameter.
Be careful not to use
different time zones in each parameter unless that is intended.
on the various
ways to define the default time zone.
Example #2 Checking for failure
&?php$str&=&'Not&Good';//&previous&to&PHP&5.1.0&you&would&compare&with&-1,&instead&of&falseif&(($timestamp&=&strtotime($str))&===&false)&{&&&&echo&"The&string&($str)&is&bogus";}&else&{&&&&echo&"$str&==&"&.&date('l&dS&\o\f&F&Y&h:i:s&A',&$timestamp);}?&
I've had a little trouble with this function in the past because (as some people have pointed out) you can't really set a locale for strtotime. If you're American, you see 11/12/10 and think "12 November, 2010". If you're Australian (or European), you think it's 11 December, 2010. If you're a sysadmin who reads in ISO, it looks like 10th December 2011.
The best way to compensate for this is by modifying your joining characters. Forward slash (/) signifies American M/D/Y formatting, a dash (-) signifies European D-M-Y and a period (.) signifies ISO Y.M.D.
&?php
echo date("jS F, Y", strtotime("11.12.10"));
echo date("jS F, Y", strtotime("11/12/10"));
echo date("jS F, Y", strtotime("11-12-10"));
?&
Hope this helps someone!
UK dates (eg. 27/05/1990) won't work with strotime, even with timezone properly set.
/*
However, if you just replace "/" with "-" it will work fine.
&?php
$timestamp = strtotime(str_replace('/', '-', '27/05/1990'));
?&
*/
[red., derick]: What you instead should do is:
&?php
$date = date_create_from_format('d/m/y', '27/05/1990');
?&
That does not make it a timestamp, but a DateTime object, which is much more versatile instead.
For negative UNIX timestamps, strtotime seems to return the literal you passed in, or it may try to deduct the number of seconds from today's date.To work around this behaviour, it appears that the same behaviour as described in the DateTime classes applies:Specifically this line here (in the EN manual):& The $timezone parameter and the current timezone are ignored when the $time parameter either is a UNIX timestamp (e.g. @) or specifies a timezone (e.g. T15:00:00+02:00).Therefore strtotime('@-1000') returns 1000 seconds before the epoch.Hope this helps.
WARNING when using "next month", "last month", "+1 month",& "-1 month" or any combination of +/-X months. It will give non-intuitive results on Jan 30th and 31st. As described at : &?php$d = new DateTime( '' );$d-&modify( 'next month' );echo $d-&format( 'F' ), "\n";?&In the above, using "next month" on January 31 will output "March" even though you might want it to output "February". ("+1 month" will give the same result. "last month", "-1 month" are similarly affected, but the results would be seen at beginning of March.)The way to get what people would generally be looking for when they say "next month" even on Jan 30 and Jan 31 is to use "first day of next month":&?php$d = new DateTime( '' );$d-&modify( 'first day of next month' );echo $d-&format( 'F' ), "\n";?&&?php$d = new DateTime( '' );$d-&modify( 'first day of +1 month' );echo $d-&format( 'F' ), "\n";?&
I was having trouble parsing Apache log files that consisted of a time entry (denoted by %t for Apache configuration). An example Apache-date looks like: [21/Dec/:39 -0500]Apache claims this to be a 'standard english format' time. strtotime() feels otherwise. I came up with this function to assist in parsing this peculiar format.&?phpfunction from_apachedate($date){& & & & list($d, $M, $y, $h, $m, $s, $z) = sscanf($date, "[%2d/%3s/%4d:%2d:%2d:%2d %5s]");& & & & return strtotime("$d $M $y $h:$m:$s $z");}?&Hope it helps anyone else seeking such a conversion.
&?php strtotime('-5 weeks monday') ?& returns the monday of 5 weeks ago.
Adding a note to an already long page:Try to be as specific as you can with the string you pass in.& For example&?phpecho date('F', strtotime('February')); ?&is not specific enough.& Depending on the day of the month, you may get a different response.& For a non-leap year, you'll get March if the _current day of the month_ is the 29th, 30th or 31st.& If it's a leap year, you'll get March on the 30th or 31st of the month.& The same thing will happen on the 31st of any month when you pass in the name of any month with less than 31 days.& This happens because the strtotime() function will fill in missing parts from the current day.Assuming today is July 31, the timestamp returned by strtotime('February') will ultimately be seen as February 31 (non-existant obviously), which then is interpreted as March 3, thus giving a month name of March.Interestingly, adding the year or the day will give you back the expected month.
Be aware that you cannot rely on this function alone to validate a date, as it will accept insane dates like the 31st of February.Also, the '... week' functionality by itself may not do what you expect. If used on a Sunday, 'next week' will not return a timestamp of the next Monday, but of the Monday after that. Similarly, a timestamp for the Monday of the current week is returned when 'previous/last week' is used and 'this week' returns a stamp of the Monday of the next week (i.e. the following day). This is not the 'week starts on Sunday' effect, as that would mean all the timestamps returned would have to be on a Sunday and none of them are.
strtotime() also returns time by year and weeknumber. (I use PHP 5.2.8, PHP 4 does not support it.) Queries can be in two forms:
- "yyyyWww", where yyyy is 4-digit year, W is literal and ww is 2-digit weeknumber. Returns timestamp for first day of week (for me Monday)
- "yyyy-Www-d", where yyyy is 4-digit year, W is literal, ww is 2-digit weeknumber and dd is day of week (1 for Monday, 7 for Sunday)
&?php
strtotime('2009W32'); strtotime('2009W01'); strtotime(''); ?&
Weeknumbers are (probably) computed according to ISO-8601 specification, so doing date('W') on given timestamps should return passed weeknumber.
[red.: This is a bug, and should be fixed. I have file an issue]
This comment apply to PHP5+
We can now do thing like this with strtotime:
&?php
$weekMondayTime = strtotime('Monday this week');
?&
However this works based on a week starting Sunday.& I do not know if we can tweak this PHP behavior, anyone know?
If you want the timestamp of the start of the ISO Week (i.e. on Monday) as defined by ISO 8601, you can use this one liner:
&?php
$isoWeekStartTime = strtotime(date('o-\\WW')); ?&
You can also find out the start of week of any time and format it into an ISO date with another one liner like this:
&?php
$isoWeekStartDate = date('Y-m-d', strtotime(date('o-\\WW', $time)));
?&
For more information about ISO-8601 and ISO week date:
The "+1 month" issue with strtotime===================================As noted in several blogs, strtotime() solves the "+1 month" ("next month") issue on days that do not exist in the subsequent month differently than other implementations like for example MySQL.&?phpecho date( "Y-m-d", strtotime( " +1 month" ) ); echo date( "Y-m-d", strtotime( " +2 month" ) ); ?&&?phpSELECT DATE_ADD( '', INTERVAL 1 MONTH ); ?&
It took me a while to notice that strtotime starts searching from just after midnight of the first day of the month. So, if the month starts on the day you search for, the first day of the search is actually the next occurrence of the day.
In my case, when I look for first Tuesday of the current month, I need to include a check to see if the month starts on a Tuesday.
&?php
if (date("l", strtotime("$thisMonth $thisYear"))=='Tuesday') {
& echo "&p&This month starts on a Tuesday. Use \"$thisMonth $thisYear\" to check for first Tuesday.&/p&\n";
} else {
& echo "&p&This month does not start on a Tuesday. Use \"first tuesday $thisMonth $thisYear\" to check for first Tuesday.&/p&\n";
}
?&
Strtotime() can be used to loop through date range.
as follows
&?php
$start = strtotime('');
$end = strtotime('');
$date = $start;
while($date & $end)
{
&& $date = strtotime("+1 day", $date);(counter)
This function DOES NOT work from left-to-right as one would think. This function parses the string as a whole, then applies the intervals by size (year, month, ...). Take the following example:&?php$Date = strtotime(''); echo date('n/j/Y', strtotime('+1 year, +7 days', $Date)); echo "&br /&";echo date('n/j/Y', strtotime('+7 days, +1 year', $Date)); echo "&br /&";echo date('n/j/Y', strtotime('+1 year', strtotime('+7 days', $Date))); ?&
Observed date formats that strtotime expects, it can be quite confusing, so hopefully this makes things a little clearer for some.mm/dd/yyyy - 02/01/2003& - strtotime() returns : 1st February 2003mm/dd/yy&& - 02/01/03& & - strtotime() returns : 1st February 2003yyyy/mm/dd& -
- strtotime() returns : 1st February 2003dd-mm-yyyy - 01-02-2003& - strtotime() returns : 1st February 2003yy-mm-dd&& - 03-02-01& & - strtotime() returns : 1st February 2003yyyy-mm-dd - & - strtotime() returns : 1st February 2003
Unlike "yesterday 14:00", "14:00 yesterday" will return 00:00 of yesterday.
You are not restricted to the same date ranges when running PHP on a 64-bit machine. This is because you are using 64-bit integers instead of 32-bit integers (at least if your OS is smart enough to use 64-bit integers in a 64-bit OS)The following code will produce difference output in 32 and 64 bit environments.var_dump(strtotime(''));32-bit PHP: bool(false)64-bit PHP: int(-)This is true for php 5.2.* and 5.3Also, note that the anything about the year 10000 is not supported. It appears to use only the last digit in the year field. As such, the year 10000 is interpretted as the year
as 2007, etc
strtotime() seems to treat dates delimited by slashes as m/d/y and dates delimited by dashes are treated as d-m-y.
&?php
print date('Y-m-d', strtotime("06/08/2008"));
?&
&?php
print date('Y-m-d', strtotime("06-08-2008"));
?&
Using PHP 5.2.6
There is a change in the strtotime function...&?phpecho date('Y', strtotime(' 00:00:00'));?&
strtotime() produces different output on 32 and 64 bit systems running PHP 5.3.3 (as mentioned previously).& This affects the "zero date" (" 00:00:00") as well as dates outside the traditional 32 date range.strtotime(" 00:00:00") returns FALSE on a 32 bit system.strtotime(" 00:00:00") returns - on a 64 bit system.
when using PHP 5.3, you must use date_default_timezone_set() to set the time zone otherwise you will get warning similar to this (if you have display_errors=On)—Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Dubai' for '4.0/no DST' instead in path/to/php/script.phpon line ##Example:date_default_timezone_set('Indian/Mauritius');For a list of supported timezones in PHP, see
Be aware that if you are running 5.2.8, there is a memory leak with this function and it could cost someone valuable time finding out what the problem was. Per usual, running the latest (minor) version tends to be a good idea.See here:
Here's a hack to make this work for MS SQL's datetime junk, since strtotime() has issues with fractional seconds.&?php$MSSQLdatetime = "Feb& 7 :06:697PM";$newDatetime = preg_replace('/:[0-9][0-9][0-9]/','',$MSSQLdatetime);$time = strtotime($newDatetime);echo $time."\n";?&
Here is a list of differences between PHP 4 and PHP 5 that I have found(specifically PHP 4.4.2 and PHP 5.2.3).&?php$ts_from_nothing = strtotime();var_dump($ts_from_nothing);$ts_from_null = strtotime($null);var_dump($ts_from_null)...$ts_from_empty = strtotime("");var_dump($ts_from_empty);$ts_from_bogus = strtotime("not a date");var_dump($ts_from_bogus);?&
You should play around with strtotime() before you decide what it can't do.& for example:&?phpdate('m/d/y', strtotime('first day')); date('m/d/y', strtotime('last day')); date('m/d/y', strtotime('last day next month')); date('m/d/y', strtotime('last day last month')); date('m/d/y', strtotime('2009-12 last day')); date('m/d/y', strtotime('2009-03 last day')); date('m/d/y', strtotime('2009-03')); date('m/d/y', strtotime('last day of march 2009')); date('m/d/y', strtotime('last day of march')); ?&
strtotime is awesome for converting dates.
in this example i will make an RSS date, an
ATOM date, then convert them to a human
readable m/d/Y dates.
&?php
$rss = date("r");
$atom = date("c");
$human1 = date('m/d/Y', strtotime($rss));
$human2 = date('m/d/Y', strtotime($atom));
echo $rss."&br /&".$atom."&br /&".$human1."&br /&".$human2;
?&
NOTE: strtotime returns different values when the Week day does not match the date.
Simple example:
&?php
$d1 = strtotime("26 Oct :00 +0100");
$d2 = strtotime("Tue, 26 Oct :00 +0100");
$d3 = strtotime("Sun, 26 Oct :00 +0100"); echo $d1; echo $d2; echo $d3; ?&
Sometime I found RSS feeds that contains week days that do not match the date.
A possible solution is to remove useless week day before passing the date string into strtotime, example:
&?php
&& $date_string = "Sun, 26 Oct :00 +0100";
&& if( ($comma_pos = strpos($date_string, ',')) !== FALSE )
& & & $date_string = substr($date_string, $comma_pos + 1);
&& $d3 = strtotime($date_string);
?&
This date is interpreted as American date (MM/DD/YYYY):$date = "06/10/"; // Oct 10, 2011This date is interpreted as European date (DD/MM/YYYY):$otherDate = "06-10-"; // Jun 10, 2011That's why you see those differences.
A useful testing tool for strtotime() and unix timestamp conversion:
// small function auto detect to convert datefunction formatDate($date){& & if (strpos($date,'/') !== false) :& & & & $date = str_replace('/', '-', $date);& & & & $date = date('Y-m-d h:i:s', strtotime($date));& & else :& & & & $date = date('d-m-Y h:i:s', strtotime($date));& & & & $date = str_replace('-', '/', $date);& && & return $}
To get the start of the current week this code works fine when the week starts on Sundays.&?php strtotime('this Monday'); ?&To get the timestamp of the start of a week starting on Mondays (as defined by ISO 8601) this shoud do the trick.&?php strtotime('next Monday -1 week'); ?&
&?phpdate_default_timezone_set("Europe/Kiev");echo "Kiev:".strtotime("now");echo "&br&&br&"; date_default_timezone_set("America/New_York"); echo "New-York:".strtotime("now");echo "&br&&br&";date_default_timezone_set("UTC"); echo "UTC:".strtotime("now");echo "&br&==========================&br&";date_default_timezone_set("Europe/Kiev");echo "Kiev:".strtotime("midnight");echo "&br&&br&";date_default_timezone_set("America/New_York"); echo "New-York:".strtotime("midnight");echo "&br&&br&";date_default_timezone_set("UTC"); echo "UTC:".strtotime("midnight");echo "&br&&br&";?&result:Kiev:New-York:UTC:==========================Kiev:New-York:UTC:
I was doing work with cisco phone systems, and thy record their times as NTP Format.strtotime() doesnt process the whole NTP timestamp, off the bat, so if you want a quick function to work I bashed this together pretty quickly, there are probably more efficent ways of processing this, but it gets the job done. Enjoy.[code]&?phpfunction NTPtoUnixtime($ntptime){& & $explodedNTPtime = explode(" ", $ntptime,2);& & $startOfDay = strtotime("Today");& & $timeThroughDay = strtotime($explodedNTPtime[0]) - $startOfDay ;& & return strtotime($explodedNTPtime[1])+$timeThroughDay;}$ntpTime = "09:49:22.897 NZDT Mon Feb 20 2012"; echo NTPtoUnixtime($ntpTime);?&[/code]
If you want to confront a date stored into mysql as a date field (not a datetime) and a date specified by a literal string, be sure to add "midnight" to the literal string, otherwise they won't match:&?phpecho strtotime(''); echo strtotime('first day of last month'); echo strtotime('midnight first day of last monty');?&
The following might produce something different than you might expect:
&?php
& & echo date('l, F jS Y', strtotime("third wednesday", strtotime(""))) . "&br&";
& & echo date('l, F jS Y', strtotime("third sunday", strtotime("")));
?&
Produces:
Wednesday, November 22nd 2006
Sunday, January 22nd 2006
The problem stems from strtotime when the requested day falls on the date passed to strtotime. If you look at your calendar you will see that they should return:
Wednesday, November 15th 2006
Sunday, January 15th 2006
Because the date falls on the day requested it skips that day.
If you look for function to convert date from RSS pubDate, always make sure to check correct input format, found that for date("r") or "D, d M o G:i:s T" strtotime may return wrong result.
Another way to get the last day of a given month is to use date('t');
0s or 00s for day or month will wrap around to the previous month or year (respectively)for example,&?phpecho date('Y-m-d',strtotime('')); echo date('Y-m-d',strtotime('')); echo date('Y-m-d',strtotime('')); echo date('Y-m-d',strtotime(''));
Seems in PHP5 there are new values that can be passed to the function:
&?php
echo time();
echo '&br&';
echo strtotime('noon');
echo '&br&';
echo strtotime('midnight');
echo '&br&';
echo strtotime('10am');
echo '&br&';
echo strtotime('2pm');
?&
I needed to generate timestamps for specific days of the week in a month (e.g. the 2nd wednesday or the 3rd friday).& After messing about with different syntax, I found this works pretty consistently:
&?php
strtotime('+0 week sun nov 2009'); strtotime('+1 week sun nov 2009'); strtotime('-1 week sun nov 2009'); ?&
This is helping me considerably in parsing ical spec's RRULE sets for example.A year has 12 months.(同义句转换)______,_______,_______,_______in a year._百度作业帮
拍照搜题,秒出答案
A year has 12 months.(同义句转换)______,_______,_______,_______in a year.
A year has 12 months.(同义句转换)______,_______,_______,_______in a year.
There are 12 months in a year.希望能够帮到楼主
用there be句型来表示某处有某物There are 12 months in a year求助英文统计学题Let X represent the number of visits to a GP over the last 12 months.From past recordx 0 1 2 3 5P(X=x) 0.5 0.2 0.1 0.1 0.1What is the expected number of visits given that a patient has had at least one visit?_百度作业帮
拍照搜题,秒出答案
求助英文统计学题Let X represent the number of visits to a GP over the last 12 months.From past recordx 0 1 2 3 5P(X=x) 0.5 0.2 0.1 0.1 0.1What is the expected number of visits given that a patient has had at least one visit?
求助英文统计学题Let X represent the number of visits to a GP over the last 12 months.From past recordx 0 1 2 3 5P(X=x) 0.5 0.2 0.1 0.1 0.1What is the expected number of visits given that a patient has had at least one visit?
我有个小问题,你是看不懂题目还是看懂了不会做.我先把题目给你翻译一下吧让X表示在过去12个月内访问GP的访问者的个数,根据过去的经验数据,我们有X=0,1,2,3,5的时候的对应的概率问题问的是,在人数至少为1的情况下,访问者数量的条件期望是多少?希望我翻译清楚了.
E(X)=p(x=i)*x=0*0.5+1*0.2+2*0.1+3*0.1+5*0.1=1.2

我要回帖

更多关于 months 的文章

 

随机推荐