【问题标题】:how to get date Object when select from dropdown list从下拉列表中选择时如何获取日期对象
【发布时间】:2016-06-30 10:38:14
【问题描述】:

我有一个下拉列表(附截图),当我们选择像今年这样的任何一个时,我们如何使用 javascript、angular js 使用日期对象在后端发送 StartIndex 和 EndIndex。 在此先感谢您将获得任何帮助

StatIndex:2016-01-01T00:00:00+5:30
EndIndex :2016-12-31T23:59:59+5:30

code for Index Range 
 this.indexRanges = ['This Year', 'Last Year', 'This Quarter', 'Last Quarter', 'This Month', 'Last Month', 'This Week',
                    'Last Week', 'Last 72 Hours', 'Last 48 Hours', 'Last 24 Hours', 'Today', 'Yesterday', 'Last Hours', 'This Hours',
                    'This 30 Minutes', 'Last 30 Minutes', 'This 15 Minutes', 'Last 15 Minutes', 'This 10 Minutes', 'Last 10 Minutes'];

【问题讨论】:

  • 如果我选择“上周”作为输入,你想要什么输出?
  • 嗨哈桑谢谢你的回复,我想要的是 startIndex:2016-03-07T00:00:00+05:30 EndIndex:2016-03-14T23:59:59+05:30
  • 你必须通过你的代码来实现这个(意味着通过实现不是javascript或angular js的内置功能的东西)你没有直接的方法可以做到这一点
  • 感谢 HassanTariq
  • 嗨 hassan tariq,有没有办法在不使用任何库的情况下使用 javascript 设置 UTC 时区

标签: javascript jquery angularjs typescript


【解决方案1】:

正如@Hassan Tariq 在 cmets 中提到的,您需要为它编写自己的方法。为了帮助您,有一个很好的图书馆可以玩日期moment.js

【讨论】:

    【解决方案2】:

    使用javascript,angular js使用日期对象发送后端

    你最想知道开始日期:

    StatIndex:2016-01-01T00:00:00+5:30
    

    使用Date 构造函数可以很容易地将其转换为Date 对象。例如:

    var StatIndex = '2016-01-01T00:00:00+5:30';
    const date = Date(StatIndex);
    const toSend = {date:date};
    const json = JSON.stringify(toSend);
    

    【讨论】:

    • 我们不能使用 2017 年的静态值,它不会起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-20
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多