通過天數得到日期,並存入資料庫

2021-08-20 23:21:31 字數 1268 閱讀 8002

前提概要:

優惠券發放的有效性:

1、通過設定「有效開始時間」、「有效結束時間」來控制優惠券的有效性

2、通過給定有效時長,自動計算多少天後失效

js所需效果:1、開始時間-結束時間=失效天數

2、 當前時間+失效天數=結束時間

核心**:

1、通過開始時間和結束時間得到失效天數

a.通過id獲取標籤的值

var expirydatestart = $('#expirydatestart').val();

var expirydateend = $('#expirydateend').val();

b.將得到的日期格式,去除/-後

var exps = new date(expirydatestart.replace(/-/g, "/"));

var expe = new date(expirydateend.replace(/-/g, "/"));

c.得到的整數計算天數

var cycle = parseint((expe.gettime() - exps.gettime()) / (1000 * 60 * 60 * 24));

$('#cycletime').val(cycle);

2、通過當前時間和失效天數,得到失效日期

var nowdate = new date();

var newdate = new date();

var newtimes = newdate.gettime() + (cycletime * 24 * 60 * 60 * 1000);

newdate.settime(newtimes);

$('#expirydatestart').val(nowdate.tolocaledatestring());

$('#expirydateend').val(newdate.tolocaledatestring());

拓展:tolocaledatestring() 方法可根據本地時間把 date 物件的日期部分轉換為字串,並返回結果。

定時抓取資料並存入資料庫

其實,這部分主要是實現定時抓取資料的程式,資料的抓取以及儲存程式已寫 從tushare獲取歷史 資料 抓取交易日 周一到周五 資料,定時為每天的15 30抓取,其中主要使用到了schedule模組用於定時執行任務 如下 import schedule import time from datetim...

雪球網爬取資料並存入資料庫

from urllib import request import json import pymysql class mysql connect object 初始化的建構函式 def init self self.db pymysql.connect host 127.0.0.1 user ro...

使用python訪問檔案,並存入資料庫中

使用python讀取檔案並存入資料庫中。usr local bin python import os,mysqldb conn mysqldb.connection localhost username yourpasswd test cur conn.cursor cur.execute drop...