在连续,今天和明天之前获取日期

时间:2017-04-21 14:44:09

标签: javascript jquery html angular date

我怎样才能连续一天前来?例如,我有这个HTML:

<ul>
<li (click)="prevDay()"></li>
</ul>

<div>{{day}}</div>

JS:

dayBefore() {
        let now: any = new Date();
        this.days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
        this.day = this.days[now.getDay() - 1];
}

这样我只得到昨天,但我需要它。当我再次点击<div>{{day}}</div>时,我需要它在“昨天”前一天前往。等等。所以,周四,周三,周二等。

编辑:今天和明天都一样......

3 个答案:

答案 0 :(得分:1)

您可以尝试以下操作:

    <script src="https://code.angularjs.org/2.0.0-alpha.26/angular2.sfx.dev.js"></script>

<script>
    function AppComponent() {
            this.day = '';
        this.decrement = 0;
        this.days =   ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
        this.dayBefore = function() {

                    var now = new Date();  
          this.decrement+=1;
          var newDate = this.decrementDays(now, this.decrement);
          this.day = this.days[newDate.getDay()];               
        },
        this.decrementDays = function addDays(date, days)  {
            return new Date(
        date.getFullYear(),
        date.getMonth(),
        date.getDate() - days,
        date.getHours(),
        date.getMinutes(),
        date.getSeconds(),
        date.getMilliseconds()
        );
        }

    }

    AppComponent.annotations = [
      new angular.ComponentAnnotation({
        selector: 'my-app'
      }),
      new angular.ViewAnnotation({
        template: '<ul>' +
'<li (click)="dayBefore()">aaaaa</li>' +
'</ul>' +
'<div>{{day}}</div>',
        directives: [angular.NgFor]
      })
    ];

    document.addEventListener('DOMContentLoaded', function() {
      angular.bootstrap(AppComponent);
    });

</script>

<my-app></my-app>

答案 1 :(得分:1)

在您的控制器中,仅初始化天数数组

的新日期
With Data(R_ID,    mDate,    Col_A,   Col_B,   Col_C) as (
    SELECT 158,   20161008,    01,      99,     99 FROM DUAL UNION ALL
    SELECT 158,   20161012,    01,      01,     99 FROM DUAL UNION ALL
    SELECT 158,   20161019,    01,      02,     10 FROM DUAL UNION ALL
    SELECT 158,   20161022,    99,      01,     10 FROM DUAL UNION ALL
    SELECT 160,   20161006,    01,      99,     01 FROM DUAL UNION ALL
    SELECT 160,   20161011,    99,      01,     99 FROM DUAL UNION ALL
    SELECT 160,   20161017,    99,      01,     10 FROM DUAL UNION ALL
    SELECT 167,   20161013,    99,      01,     01 FROM DUAL UNION ALL
    SELECT 167,   20161016,    99,      02,     99 FROM DUAL UNION ALL
    SELECT 167,   20161020,    02,      01,     10 FROM DUAL),

MinRID as (SELECT R_ID, Min(mDate) MinDate from Data GROUP BY R_ID),
MaxRID as (SELECT R_ID, Max(mdate) MaxDate from Data GROUP BY R_ID),
Result as (SELECT A.R_ID, A.mDate, A.COL_A, A.COL_B, A.Col_C, 'Entry Record' as RecType
                FROM Data A
                INNER JOIN MinRID  B
                  on B.R_ID = A.R_ID
                 and B.MinDate = A.mDate

                UNION ALL

                SELECT A.R_ID, A.mDate, A.COL_A, A.COL_B, A.Col_C, 'Exit Record' as RecType
                FROM Data A
                INNER JOIN maxRID C
                  on C.R_ID = A.R_ID
                 and C.MaxDate = A.mDate)
SELECT * FROM Result ORDER BY R_ID, MDATE 

所以你有今天约会。然后在更改日期的方法中更新您的日期。

import java.util.ArrayList;
import java.util.List;
class pairwiseCipher{
  public static void main(String[] args){

      char[] key= {'M', 'O', 'N', 'C', 'L', 'E', 'T', 'A', 'B', 'D', 'F', 'G', 'H', 'I', 'J', 'K', 'P', 'Q', 'R', 'S', 'U','V', 'W','X','Y','Z'};
      char[] old = null;
      char[][] neww = null;
      char[][] ans = null;
      String msg= "Fish are birds without wings and birds are fish without fins";
      msg = msg.toUpperCase();

      msg = msg.replace(' ', 'X');
      System.out.println(msg);
      old = msg.toCharArray();
      neww = new char[msg.length()/2][2];
      ans = new char[msg.length()/2][2];
      for(int i=0,j=0; i<msg.length() ; i=i+2,j+=1){
          neww [j][0] = old[i];
          neww [j][1] = old[i+1];
      }

      //this is just to display characters in pairs
      for(int j=0; j<neww.length; j++){
          System.out.print(neww[j][0]+""+neww[j][1] + " ");
      }

      System.out.println();
      List<Character> cList = new ArrayList<Character>();
      for(char c : key) {
          cList.add(c);
      }

      for(int j=0; j<neww.length; j++){

          int x = (cList.indexOf(neww[j][1]) + 1 ) == 26 ? 0 : (cList.indexOf(neww[j][1]) + 1 );
          int y = (cList.indexOf(neww[j][0]) - 1 ) == -1 ? 25 : (cList.indexOf(neww[j][0]) - 1 );

         ans[j][0] = cList.get(x);
         ans[j][1] = cList.get(y);
      }

      for(int j=0; j<ans.length; j++){
          System.out.print(ans[j][0]+""+ans[j][1] + " ");
      }
      //System.out.println(cList.get(0));

  }
}

而且,在你的HTML中

private myDate=new Date();
private days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
private day = this.days[this.myDate.getDay()];;

答案 2 :(得分:1)

你应该使用如下,

  currentPos=5;
  today : string= 'Friday'
  days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];

  constructor() {
    this.today=this.days[this.currentPos];
  }
  prev(){
    //this.daysArray.push(this.days[this.currentPos]);
    if(this.currentPos>0){
      this.currentPos--;
      this.today=this.days[this.currentPos];

    }
    else if(this.currentPos==0){
      this.today=this.days[0]
      this.currentPos=6;
    }


  }
}

<强> LIVE DEMO