我需要从给定日期减去21个月.
我在下面给出的解决方案只需要我到达给定年份的第一个月:(
[a,b,c]= datevec(date);
b= b-21;
datestr(datenum(a,b,c)) %--> 11-Jan-2011 (WRONG).
Run Code Online (Sandbox Code Playgroud)
我希望答案是2009年6月11日.
我正在使用此代码:
//get days
$a = date_create($arrive);
$d = date_create($leave);
//$days = date_diff($d,$a);
echo '<input type="hidden" id="days" value="'.date_diff($d,$a).'"/>';
Run Code Online (Sandbox Code Playgroud)
并获得此错误:可捕获的致命错误:类DateInterval的对象无法转换为字符串
我不知道如何解决这个问题.
关于date_diffPHP函数有很多问题.但我觉得有点不同,因为我得到了一个相当不寻常的结果.以下是我的代码:
$today = date( 'd-m-Y', strtotime( "now" ) );
$selectDay = date( 'd-m-Y', strtotime( $row->BOOKING_DATE ));
$interval = date_diff( $selectDay, $today );
Run Code Online (Sandbox Code Playgroud)
结果我得到了:
Warning: date_diff() expects parameter 1 to be DateTime, string given in...
Run Code Online (Sandbox Code Playgroud)
如你所见$ $和$ selectDay都是日期.有什么建议?注意:我有PHP版本5.3
我有2个time()值,例如:
1379078542
1379078574
Run Code Online (Sandbox Code Playgroud)
我如何解决他们的不确定性并将输出显示为年,月,周,日,小时,分钟,秒等.
我认为上面的2个值有32秒的差异,所以在这种情况下,我想显示32秒.
我需要将当前日期与开始日期进行比较,想法是每个月+ 1天它将返回,好像只有一个月过去了.因此,如果开始日期是2014-10-27,那么在2014-11-27它仍将显示不到一个月前,并且在2014-11-28它将显示一个多月前.
目前我有:
$start_datetime = '2014-10-27';
// true if my_date is more than a month ago
if (strtotime($start_datetime) < strtotime('1 month ago')){
echo ("More than a month ago...");
} else {
echo ("Less than a month ago...");
}
Run Code Online (Sandbox Code Playgroud) 我试图获取PHP中两个DateTimes之间的分钟数:
$time = new DateTime($dateString);
$now = new DateTime;
$diff = $time->diff($now);
echo $diff->format('%m');
Run Code Online (Sandbox Code Playgroud)
结果始终为0,尽管DateTimes相隔几个小时.我怎么能以正确的方式做到这一点?
我有这个代码,在关于框中显示一些构建信息:
private void frmAbout_Load(object sender, EventArgs e)
{
Version versionInfo =
Assembly.GetExecutingAssembly().GetName().Version;
lblVersion.Text = String.Format("Version {0}.{1}",
versionInfo.Major.ToString(), versionInfo.Minor.ToString());
String versionStr = String.Format("{0}.{1}.{2}.{3}",
versionInfo.Major.ToString(), versionInfo.Minor.ToString(),
versionInfo.Build.ToString(), versionInfo.Revision.ToString());
lblBuild.Text = String.Format("Build {0}", versionStr);
DateTime startDate = new DateTime(2000, 1, 1); // The date from
whence the Build number is incremented (each day, not each
build; see http://stackoverflow.com/questions/27557023/how-can-
i-get-the-build-number-of-a-visual-studio-project-to-increment)
int diffDays = versionInfo.Build;
DateTime computedDate = startDate.AddDays(diffDays);
lblLastBuilt.Text += computedDate.ToLongDateString();
}
Run Code Online (Sandbox Code Playgroud)
今天看起来像这样:

"问题"是屏幕房地产有限,而"2015年2月4日"等日期对我来说看起来很怪异(我更喜欢"2015年2月4日").
我可以像这样强行从ToLongDateString()返回的字符串强制执行:
String lds = computedDate.ToLongDateString();
lds = // find leading …Run Code Online (Sandbox Code Playgroud) date-math ×7
datetime ×5
php ×5
date ×2
c# ×1
dateinterval ×1
matlab ×1
text-parsing ×1
timestamp ×1