本文整理汇总了PHP中Date::getMonth方法的典型用法代码示例。如果您正苦于以下问题:PHP Date::getMonth方法的具体用法?PHP Date::getMonth怎么用?PHP Date::getMonth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Date
的用法示例。
在下文中一共展示了Date::getMonth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(Date $base, $weekStart = Timestamp::WEEKDAY_MONDAY)
{
$firstDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-01');
$lastDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-' . date('t', $base->toStamp()));
$start = $firstDayOfMonth->getFirstDayOfWeek($weekStart);
$end = $lastDayOfMonth->getLastDayOfWeek($weekStart);
$this->monthRange = DateRange::create()->lazySet($firstDayOfMonth, $lastDayOfMonth);
$this->fullRange = DateRange::create()->lazySet($start, $end);
$rawDays = $this->fullRange->split();
$this->fullLength = 0;
foreach ($rawDays as $rawDay) {
$day = CalendarDay::create($rawDay->toStamp());
if ($this->monthRange->contains($day)) {
$day->setOutside(false);
} else {
$day->setOutside(true);
}
$this->days[$day->toDate()] = $day;
$weekNumber = floor($this->fullLength / 7);
if (!isset($this->weeks[$weekNumber])) {
$this->weeks[$weekNumber] = CalendarWeek::create();
}
$this->weeks[$weekNumber]->addDay($day);
++$this->fullLength;
}
++$this->fullLength;
}
示例2: getSpan
/**
* A method that can be inherited and used by children classes to get the
* required date span of a statistics page.
*
* @param object $oCaller The calling object. Expected to have the
* the following class variables:
* $oCaller->aPlugins - An array of statistics fields plugins
* $oCaller->oStartDate - Will be set by method
* $oCaller->spanDays - Will be set by method
* $oCaller->spanWeeks - Will be set by method
* $oCaller->spanMonths - Will be set by method
* @param array $aParams An array of query parameters for
* {@link Admin_DA::fromCache()}.
*/
function getSpan(&$oCaller, $aParams)
{
$oStartDate = new Date(date('Y-m-d'));
$oStartDate->setHour(0);
$oStartDate->setMinute(0);
$oStartDate->setSecond(0);
// Check span using all plugins
foreach ($oCaller->aPlugins as $oPlugin) {
$aPluginParams = call_user_func(array($oPlugin, 'getHistorySpanParams'));
$aSpan = Admin_DA::fromCache('getHistorySpan', $aParams + $aPluginParams);
if (!empty($aSpan['start_date'])) {
$oDate = new Date($aSpan['start_date']);
$oDate->setTZbyID('UTC');
if ($oDate->before($oStartDate)) {
$oDate->convertTZ($oStartDate->tz);
$oStartDate = new Date($oDate);
}
}
}
$oStartDate->setHour(0);
$oStartDate->setMinute(0);
$oStartDate->setSecond(0);
$oNow = new Date();
$oSpan = new Date_Span(new Date($oStartDate), new Date($oNow->format('%Y-%m-%d')));
// Store the span data required for stats display
$oCaller->oStartDate = $oStartDate;
$oCaller->spanDays = (int) ceil($oSpan->toDays());
$oCaller->spanWeeks = (int) ceil($oCaller->spanDays / 7) + ($oCaller->spanDays % 7 ? 1 : 0);
$oCaller->spanMonths = ($oNow->getYear() - $oStartDate->getYear()) * 12 + ($oNow->getMonth() - $oStartDate->getMonth()) + 1;
// Set the caller's aDates span in the event that it's empty
if (empty($oCaller->aDates)) {
$oCaller->aDates['day_begin'] = $oStartDate->format('%Y-%m-%d');
$oCaller->aDates['day_end'] = $oNow->format('%Y-%m-%d');
}
}
示例3: testDateOffset
public function testDateOffset()
{
$date = new Date('2015-04-25+01:00');
$this->assertEquals(2015, $date->getYear());
$this->assertEquals(4, $date->getMonth());
$this->assertEquals(25, $date->getDay());
$this->assertEquals(3600, $date->getOffset());
$this->assertInstanceOf('DateTimeZone', $date->getTimeZone());
$this->assertEquals('2015-04-25+01:00', $date->toString());
}
示例4: testSetByLocaleStringShort
function testSetByLocaleStringShort()
{
$date = new Date();
$locale = new Locale('en');
$date->setByLocaleString($locale, 'Thu 20 Jan 2005', '%a %d %b %Y');
$this->assertEqual($date->getMonth(), 1);
$this->assertEqual($date->getYear(), 2005);
$this->assertEqual($date->getDay(), 20);
}
示例5: Date
/**
* Adds a holiday to the driver's holidays
*
* @param string $internalName internal name - must not contain characters
* that aren't allowed as variable-names
* @param mixed $date date (timestamp | string | PEAR::Date object)
* @param string $title holiday title
*
* @access protected
* @return void
*/
function _addHoliday($internalName, $date, $title)
{
if (!is_a($date, 'Date')) {
$date = new Date($date);
}
$this->_dates[$internalName] = $date;
$this->_titles['C'][$internalName] = $title;
$isodate = mktime(0, 0, 0, $date->getMonth(), $date->getDay(), $date->getYear());
if (!isset($this->_holidays[$isodate])) {
$this->_holidays[$isodate] = array();
}
array_push($this->_holidays[$isodate], $internalName);
array_push($this->_internalNames, $internalName);
}
示例6: datePicker
private function datePicker(Date $dateObj)
{
$yStart = empty($this->yearStart) ? "-3" : $this->yearStart;
$yEnd = empty($this->yearEnd) ? "+3" : $this->yearEnd;
return $this->ascList("d", 1, 31, $dateObj->getDay()) . $this->ascList("m", 1, 12, $dateObj->getMonth()) . $this->ascList("y", $this->getEvaledYear($yStart), $this->getEvaledYear($yEnd), $dateObj->getYear());
}
示例7: isEquals
public function isEquals(Date $date)
{
return $this->year === $date->getYear() && $this->month === $date->getMonth() && $this->day === $date->getDay();
}
示例8: getIntervalsRemaining
/**
* A method to get the number of operation intervals in a given
* start & end date range must be valid OI start & end date range
*
* @static
* @param object $oStartDate PEAR::Date object
* @param object $oEndDate PEAR::Date object
* @return integer number of operation intervals remaining
*/
function getIntervalsRemaining($oStartDate, $oEndDate)
{
$operationIntervalSeconds = OX_OperationInterval::getOperationInterval() * 60;
// Convert to UTC
$oStartCopy = new Date($oStartDate);
$oStartCopy->toUTC();
$oEndCopy = new Date($oEndDate);
$oEndCopy->toUTC();
// Get timestamp of start date/time - in seconds
$startDateSeconds = mktime($oStartCopy->getHour(), $oStartCopy->getMinute(), $oStartCopy->getSecond(), $oStartCopy->getMonth(), $oStartCopy->getDay(), $oStartCopy->getYear());
// Get timestamp of end date/time - in seconds
$endDateSeconds = mktime($oEndCopy->getHour(), $oEndCopy->getMinute(), $oEndCopy->getSecond(), $oEndCopy->getMonth(), $oEndCopy->getDay(), $oEndCopy->getYear());
// calculate interval length in seconds
$interval = $endDateSeconds - $startDateSeconds;
// find number of operation intervals during interval
return $interval <= 0 ? 0 : round($interval / $operationIntervalSeconds);
}
示例9: transferFinishedTransactions
function transferFinishedTransactions($account, $plannedTransaction)
{
$now = new Date();
$date = new Date($plannedTransaction->getBeginDate());
$dayOfMonth = $date->getDay();
//While we are before now and the end date of this transaction
while (!$date->after($now) && !$date->after(is_null($tmp = $plannedTransaction->getEndDate()) ? new Date('9999-12-31') : $tmp)) {
$account->addFinishedTransaction($plannedTransaction->getAmount(), $plannedTransaction->getTitle(), $plannedTransaction->getDescription(), new Date($date), $plannedTransaction->getTransactionPartner(), $plannedTransaction->getCategory(), $plannedTransaction->getOutsideCapital(), false, true);
//do the date calculation
switch ($plannedTransaction->getRepeatUnit()) {
case 'day':
$date->addSeconds($plannedTransaction->getRepeatFrequency() * 24 * 60 * 60);
break;
case 'week':
$date->addSeconds($plannedTransaction->getRepeatFrequency() * 7 * 24 * 60 * 60);
break;
case 'month':
//Set the month
$date = new Date(Date_Calc::endOfMonthBySpan($plannedTransaction->getRepeatFrequency(), $date->getMonth(), $date->getYear(), '%Y-%m-%d'));
//And count back as far as the last valid day of this month
while ($date->getDay() > $dayOfMonth) {
$date->subtractSeconds(24 * 60 * 60);
}
break;
case 'year':
$newYear = $date->getYear() + $plannedTransaction->getRepeatFrequency();
if ($dayOfMonth == 29 && $date->getMonth() == 2 && !Date_Calc::isLeapYear($newYear)) {
$date->setDay(28);
} else {
$date->setDay($dayOfMonth);
}
$date->setYear($newYear);
break;
default:
throw new BadgerException('Account', 'IllegalRepeatUnit', $plannedTransaction->getRepeatUnit());
exit;
}
}
}
示例10: isToday
/**
* Checks if the given day is the current day
*
* @param mixed $stamp Any timestamp format recognized by Pear::Date
*
* @return boolean
* @access protected
*/
function isToday($stamp)
{
static $today = null;
if (is_null($today)) {
$today = new Date();
}
$date = Calendar_Engine_PearDate::stampCollection($stamp);
return $date->day == $today->getDay() && $date->month == $today->getMonth() && $date->year == $today->getYear();
}
示例11: get_prior_month
function get_prior_month($template, $userID, $connection)
{
$calc = new Date_Calc();
$beg_date = new Date();
$end_date = new Date();
$beg_date->addMonths(-1);
// Get current month dates.
$beg_date->setDayMonthYear(1, $beg_date->getMonth(), $beg_date->getYear());
$end_date->setDayMonthYear($calc->getLastDayOfMonth($beg_date->getMonth(), $beg_date->getYear()), $beg_date->getMonth(), $beg_date->getYear());
$query = "SELECT SUM(seconds) AS seconds, SUM(distance) AS distance, sbr_type FROM flmain WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='a' GROUP BY sbr_type";
$result = @mysql_query($query, $connection);
$template->setCurrentBlock("PRIORMONTH");
$template->setVariable("MONTHNAME", $beg_date->format("%B %Y"));
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
switch ($row["sbr_type"]) {
case 's':
$template->setVariable("SWIMDUR", round(convert_seconds_minutes($row["seconds"]), 2) . "min");
$template->setVariable("SWIMDIST", $row["distance"] . " yds");
break;
case 'b':
$template->setVariable("BIKEDUR", round(convert_seconds_minutes($row["seconds"]), 2) . " min");
$template->setVariable("BIKEDIST", $row["distance"] . " mi");
break;
case 'r':
$template->setVariable("RUNDUR", round(convert_seconds_minutes($row["seconds"]), 2) . " min");
$template->setVariable("RUNDIST", $row["distance"] . " mi");
break;
}
}
}
/* Get the strength minutes */
$query = "SELECT SUM(seconds) AS seconds FROM flstrength WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='a'";
$results = @mysql_query($query, $connection);
if ($results) {
while ($row = mysql_fetch_array($results)) {
$template->setVariable("STRDUR", round(convert_seconds_minutes($row["seconds"]), 2) . " min");
}
}
$template->parseCurrentBlock();
}
示例12: dosDate
/**
* Returns a date in the format used by MS-DOS.
*
* @see http://www.vsft.com/hal/dostime.htm
* @param util.Date date
* @return int
*/
protected function dosDate(Date $date)
{
return (($date->getYear() - 1980 & 0x7f) << 4 | $date->getMonth() & 0xf) << 5 | $date->getDay() & 0x1f;
}
示例13: testGetMonth
/**
* @covers Geissler\Converter\Model\Date::getMonth
*/
public function testGetMonth()
{
$this->assertInstanceOf($this->class, $this->object->setMonth(10));
$this->assertEquals(10, $this->object->getMonth());
}
示例14: getTemplateArrayCalendar
function getTemplateArrayCalendar($o_minDay, $s_date, $period)
{
// today
$today = new Date(getDateFromTimestamp(time()));
$tsToday = $today->getTimestamp();
// date asked for statistics
$dateAsked = new Date($s_date);
// used for going througt the month
$date = new Date($s_date);
$month = $date->getMonth();
$year = $date->getYear();
$prefixDay = $year . "-" . $month . "-";
$date->setDate($prefixDay . '01');
$week = $date->getWeek();
$day = 1;
$ts = $date->getTimestamp();
while ($date->getMonth() == $month) {
// day exists in stats, isn't it too old or in the future ?
if ($date->getTimestamp() >= $o_minDay->getTimestamp() && $date->getTimestamp() <= $tsToday) {
$exists = 1;
} else {
$exists = 0;
}
// day selected for stats view ?
if ($period == DB_ARCHIVES_PERIOD_DAY && $date->getDay() == $dateAsked->getDay() || $period == DB_ARCHIVES_PERIOD_WEEK && $date->getWeek() == $dateAsked->getWeek() || $period == DB_ARCHIVES_PERIOD_MONTH || $period == DB_ARCHIVES_PERIOD_YEAR) {
$selected = 1;
} else {
$selected = 0;
}
$weekNo = $date->getWeek() - $week;
if (defined('MONDAY_FIRST') && MONDAY_FIRST == 'no' && date("w", $ts) == 0) {
$weekNo += 1;
}
$dayOfWeek = (int) (!defined('MONDAY_FIRST') || MONDAY_FIRST == 'yes' ? date("w", $ts) == 0 ? 6 : date("w", $ts) - 1 : date("w", $ts));
$return[$weekNo][$dayOfWeek] = array('day' => substr($date->getDay(), 0, 1) === '0' ? substr($date->getDay(), 1, 2) : $date->getDay(), 'date' => $date->get(), 'exists' => $exists, 'selected' => $selected);
$date->addDays(1);
//these 2 lines useless? to check
$ts = $date->getTimeStamp();
$date->setTimestamp($ts);
}
foreach ($return as $key => $r) {
$row =& $return[$key];
for ($i = 0; $i < 7; $i++) {
if (!isset($row[$i])) {
$row[$i] = "-";
}
}
ksort($row);
}
return $return;
}
示例15: updateDuplicarTareaFromRequest
/**
* Actualiza los datos de la tarea duplicada.
* @version 26-02-09
* @author Ana Martín
*/
protected function updateDuplicarTareaFromRequest()
{
$tarea = $this->getRequestParameter('tarea');
$value = sfContext::getInstance()->getI18N()->getTimestampForCulture($tarea['fecha_inicio']['date'], $this->getUser()->getCulture());
$mi_date = new Date($value);
$mi_date->setHours(isset($tarea['fecha_inicio']['hour']) ? $tarea['fecha_inicio']['hour'] : 0);
$mi_date->setMinutes(isset($tarea['fecha_inicio']['minute']) ? $tarea['fecha_inicio']['minute'] : 0);
$this->nueva_tarea->setFechaInicio($mi_date->getTimestamp());
if (isset($tarea['fecha_vencimiento'])) {
$value = sfContext::getInstance()->getI18N()->getTimestampForCulture($tarea['fecha_vencimiento']['date'], $this->getUser()->getCulture());
$mi_date = new Date($value);
$mi_date->setHours(isset($tarea['fecha_vencimiento']['hour']) ? $tarea['fecha_vencimiento']['hour'] : 0);
$mi_date->setMinutes(isset($tarea['fecha_vencimiento']['minute']) ? $tarea['fecha_vencimiento']['minute'] : 0);
$this->nueva_tarea->setFechaVencimiento($mi_date->getTimestamp());
} else {
if (isset($tarea['duracion'])) {
$duracion_minutos = $tarea['duracion'];
$fecha_vencimiento = mktime($mi_date->getHours(), $mi_date->getMinutes() + $duracion_minutos, 0, $mi_date->getMonth(), $mi_date->getDay(), $mi_date->getYear());
$this->nueva_tarea->setFechaVencimiento(date('Y-m-d H:i', $fecha_vencimiento));
} else {
$this->nueva_tarea->setFechaVencimiento($mi_date->getTimestamp());
}
}
if (isset($tarea['id_usuario'])) {
$this->nueva_tarea->setIdUsuario($tarea['id_usuario']);
}
}