JavaScript日期比较奇怪(JavaScript date comparison oddity)
我有一个JavaScript日期比较的问题。 我为10月31日创建了一个Date对象,而11月1日创建了另一个Date对象,但每个getTime()返回相同的数字,并且大于/小于运算符也将日期视为相等。 这是我的代码:
d1 = new Date(2012, 10, 31, 0, 0, 0, 0); d2 = new Date(2012, 11, 1, 0, 0, 0, 0); document.write(d1.getTime() + "<br />"); document.write(d2.getTime() + "<br />"); document.write((d1 < d2) + "<br />"); document.write((d1 > d2) + "<br />");
这里是输出:
1354320000000 1354320000000 false false
相同的代码可以在其他月份结束时正常工作,它似乎只是导致问题的这两个日期。
任何帮助感谢!
I have an issue with JavaScript date comparison. I create a Date object for 31st Oct, and another for 1st Nov, yet getTime() for each returns the same figure, and the greater-than / less-than operators also consider the dates equal. Here is my code:
d1 = new Date(2012, 10, 31, 0, 0, 0, 0); d2 = new Date(2012, 11, 1, 0, 0, 0, 0); document.write(d1.getTime() + "<br />"); document.write(d2.getTime() + "<br />"); document.write((d1 < d2) + "<br />"); document.write((d1 > d2) + "<br />");
And here is the output:
1354320000000 1354320000000 false false
The same code works fine around other month endings, it seems to be just these two dates that cause an issue.
Any help appreciated!
原文:https://stackoverflow.com/questions/13202844
最满意答案
你想使用
git push --force
但请记住你正在重写公共历史。重写公共历史是一个非常糟糕的主意。 任何其他可能拉过旧历史的人,如果他们从改写的历史记录中被标记或分支出来,将不得不
git pull --rebase
,甚至更糟糕的事情,所以你必须git pull --rebase
你的羞辱,让他们知道该怎么做。服务器可能不允许这样做(但会在github上)。 请参阅receive.denyNonFastForwards(git-config)
You want to use
git push --force
but please remember that you are rewriting public history.Rewriting public history is a very bad idea. Anyone else who may have pulled the old history will have to
git pull --rebase
and even worse things if they have tagged or branched from the rewritten history, so you must publish your humiliation so they know what to do.The server may not allow this (but will on github). See receive.denyNonFastForwards (git-config)
相关问答
更多-
Git:拉动重新设计的分支(Git: Pulling a rebased branch)[2021-03-03]
我的建议(或者,“如果我是橙先生,我会怎么做”)是从git fetch开始的。 现在,我将在我的回购库中有这个,这是布隆德先生在重组之后以及在“git push -f”之前执行的。 M1 - M2 - M3 \ \ \ \ A1 - A2 A1' - A2' 一个重要的区别是,我将使我的本地标签A指向rev A2,远程标签remote remotes/origin/A指向A2'(Blond先生反其道而行,本地标签A指向A2'并且remotes/ ... -
其他提交完成后,从git rebased分支中删除提交(Remove commits from git rebased branch after other commits were done)[2024-02-08]
最简单的方法是以交互方式进行rebase:checkout feature/x ,并且可以 git rebase -i E 然后只需从提示编辑的rebase脚本中删除F,G的行。 这将使您的分支看起来像 master -> A -- B -- C -- D \ feaure/x -> E -- H' -- I' \ (orphaned) F -- G -- H -- I 你也可以做同样的事情 ... -
在重新分支后,如何更新master以匹配重新发布的分支?(after rebasing on a branch, how to update master to match that rebased branch?)[2023-08-23]
删除分支并在需要的地方重新创建分支,但它会花费您的推荐日志 - 分支指向过去的记录。 两种更清洁的方式: # if you want the branch checked out: git checkout master git reset --hard# or, if it's not checked out: git branch -f master Deleting the branch and recreating it where ... -
这里有两个不同的现象。 您从gitk发布的屏幕截图仍显示旧提交。 这就是gitk的工作方式; 如果你通过按Ctrl + F5而不是F5 (那是文件>重新加载而不是文件>更新鼠标用户)重新加载,你会看到旧提交消失,因为它不再相关。 Git中有很多操作可以创建提交。 甚至更多的是在文件存储中创建文件或树对象。 许多这些对象不再使用的事实是无关紧要的。 这有很多优点。 在您的示例中,这意味着如果您认为您的rebase是一个坏主意,您的旧提交仍然存在并且可以恢复。 甚至还有一个方便的语法: topic@{1}指的是 ...
-
我如何强制重写我推送和重新发布的git分支?(How do I force the overwriting of a git branch I pushed and rebased?)[2024-02-13]
你想使用git push --force但请记住你正在重写公共历史。 重写公共历史是一个非常糟糕的主意。 任何其他可能拉过旧历史的人,如果他们从改写的历史记录中被标记或分支出来,将不得不git pull --rebase ,甚至更糟糕的事情,所以你必须git pull --rebase你的羞辱,让他们知道该怎么做。 服务器可能不允许这样做(但会在github上)。 请参阅receive.denyNonFastForwards(git-config) You want to use git push --fo ... -
是否重新分支当前分支或我们重新分支的分支(Does rebasing a branch chnage the current branch or the branch which we rebased)[2022-12-18]
git rebase master将更改new-branch上的提交历史记录。 如下图所示,假设原始提交历史是: A---B---C---G---H master \ D---E---F my-branch 执行git rebase master ,它会将更改从my-branch重新绑定到master分支。 提交历史记录如下: A---B---C---G---H---D'---E'---F' my-branch | ... -
这应该可以解决问题 git push origin branch_name -f This should do the trick git push origin branch_name -f
-
如果你处于这种类型的循环(fetch / rebase)并且一遍又一遍地看到相同的冲突,你可以激活git rerere功能。 这样可以避免为每个rebase做同样的冲突解决。 另请参阅“ 启用git rerere有什么缺点吗? ”,“ rerere的乐趣 ”和“ Rerere Your Boat ...... ”等等。 If you are in this type of cycle (fetch/rebase) and see the same conflicts over and over, you c ...
-
在git rebase之后,我的本地分支和远程分支发生了分歧(after git rebase my local branch and remote branch have diverged)[2022-06-09]
首先,你可以在这个阶段做一个git push --force ,不用担心:你说你的分支不是共享的。 因此,在服务器端更改其历史记录不会影响任何其他用户。 其次,当你改变一个分支时,你改变它的共同祖先与它的远程追踪分支( origin/xxx ) 在git rebase develop之前,你有 d--d--d (develop) \ x--x--x--x--x--X--y--y--y (my-feature) | (origin/my- ... -
不要那么改变。 合并。 即,不要在anotherBranch feature-branch上重新设置feature-branch 。 将anotherBranch合并到feature-branch 。 请注意,删除远程分支或push --force相同的分支是相同的。 在这两种情况下,您都发布了新的SHA1,重写了历史记录,这对于之前已经撤消feature-branch其他人来说可能不方便。 Don't rebase then. Merge. Ie, don't rebase feature-branch ...