gpt4 book ai didi

Javascript 提取月、日和年格式

转载 作者:行者123 更新时间:2023-11-28 06:36:20 25 4
gpt4 key购买 nike

嗨,我有以下代码,应该分别提取日、月和年部分。

  $scope.$watch('inlineDatepicker.date', function() {
alert('hey, myVar has changed!' +$scope.inlineDatepicker.date);
alert($scope.inlineDatepicker.date.getDay());
alert($scope.inlineDatepicker.date.getMonth());
alert($scope.inlineDatepicker.date.getUTCFullYear());

});

代码的问题是我可以正确提取年份,但无法正确提取日期和月份。我也试过了

    alert($scope.inlineDatepicker.date.getUTCDady());
alert($scope.inlineDatepicker.date.getUTCMonth())

日期和月份仍然错误。请让我知道如何更改它以获得正确的月份和日期值。谢谢。这是它的小工具。

http://plnkr.co/edit/8v75gsz8ODUrTfu8S0sh?p=preview

最佳答案

要获取月份中的某一天,请使用getUTCDate()
月份从零开始,因此 0 表示 1 月、12 月 11 日
示例

$scope.inlineDatepicker.date.getUTCDate(); //prints day of month
$scope.inlineDatepicker.date.getUTCMonth() + 1; //prints month, 0 based, so add 1
$scope.inlineDatepicker.date.getUTCFullYear(); //prints 2015

关于Javascript 提取月、日和年格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34254943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com