/*
根据 timestamp 去计算它所属的月份的全部 days
days数据结构为：[timestamp1, timestamp2, ...]
498524
function getMonthDays(timestamp = Date.now()) {
  const cursorDay = new Date(new Date(timestamp).setDate(1));
  const currentMonth = cursorDay.getMonth();
  const days = [];
  while (cursorDay.getMonth() === currentMonth) {
    days.push(cursorDay.getTime());
    cursorDay.setDate(cursorDay.getDate() + 1);
  }
  return days;
}
141576
private String getDateSuffix() {
		
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH); // 0 to 11
		int day = cal.get(Calendar.DAY_OF_MONTH);
		int hour = cal.get(Calendar.HOUR_OF_DAY);
		int minute = cal.get(Calendar.MINUTE);
		int second = cal.get(Calendar.SECOND);

		return String.format("-%4d-%02d-%02d_%02dh%02dm%02ds", year,
				(month + 1), day, hour, minute, second);
	}
861229
function yyyymmddhhmmss() {
  const d = new Date();
  return (
    d.getFullYear().toString() +
    padDate(d.getMonth() + 1) +
    padDate(d.getDate()) +
    padDate(d.getHours()) +
    padDate(d.getMinutes()) +
    padDate(d.getSeconds())
  );
}
1206246
function isDateSame (date1, date2, format) {
  if (date1 && date2) {
    return toDateString(date1, format) === toDateString(date2, format)
  }
  return false
}
596412
function stringToRegularHolidays (value) {
  var regular = {};
  value = value.split(',').map(x => x.trim());

  // 曜日
  regular.week = makeMap(getWeekIndex(value) || []);

  // 日
  var day = value.map(x => REG_NUM.test(x) ? x * 1 : 0)
                 .filter(x => 1 <= x && x <= 31);
  regular.day = makeMap(day);

  // 第nw曜日
  var xweek = value.map(x => {
    var m = x.match(REG_NUMYOBI);
    if (m) {
      var n = +m[1];
      n = 5 < n ? 5 : n;
      var w = getWeekIndex(m[2]);
      if (1 <= n && w !== null) {
        return n + '-' + w;
      }
    }
    return null;
  }).filter(x => x);
  regular.xweek = makeMap(xweek);
  return regular;
}
94571
def timestamp_to_days(self, timestamp):
        ''''''
        if self.tday_base is None:
            try:
                self.tday_base = matplotlib.dates.date2num(datetime.datetime.fromtimestamp(timestamp+self.timeshift))
                self.tday_basetime = timestamp
            except ValueError:
                # this can happen if the log is corrupt
                # ValueError: year is out of range
                return 0
        sec_to_days = 1.0 / (60*60*24)
        return self.tday_base + (timestamp - self.tday_basetime) * sec_to_days
605391
function getDayData(input){
    var data = csvTable(input,"\t");
    var today = new Date().getTime(); //getDateDDMMYYYY();
    var header = data[0];
    var column = 2;
    var minDiff = Number.MAX_SAFE_INTEGER;
    while(column<header.length){
        var columnDate =  new Date(header[column]+' 12:00:00 GMT-0500').getTime();
        if(Math.abs(today-columnDate)<minDiff){
            column++;
            minDiff = Math.abs(today-columnDate);
        }
        else{
            column--;
            break;
        }

    }
    if(column>=header.length){
        return null;
    }
    var result = new Array(data.length-1);
    for(var i=1;i<data.length;i++){
        result[i-1]={id:data[i][0],value:Number(data[i][column]),date:header[column]};

    }

    var table = new Array();
    table.push(result);
    for(var k=2;k<=column-1;k++){
        var row = new Array(data.length-1);
        for(var i=1;i<data.length;i++){
            row[i-1]={id:data[i][0],value:Number(data[i][k]),date:header[k]};
        }
        table.push(row);
    }

    return table;
}
115467
function fixDay(days) {
		var s = [], i;
		for (i = 1; i < days.length; i++) {
			s.push(days[i]);
		}
		s.push(days[0]);
		return s;
	}
962418
function timestamp () {
  var now = new Date()
  var diff = now.getTimezoneOffset() + 480
  now = new Date(now.getTime() + diff * 60000)

  var year = now.getFullYear()
  var month = ('0' + (now.getMonth() + 1)).slice(-2)
  var day = ('0' + now.getDate()).slice(-2)
  var hour = ('0' + now.getHours()).slice(-2)
  var minutes = ('0' + now.getMinutes()).slice(-2)
  var seconds = ('0' + now.getSeconds()).slice(-2)

  var result = '' + year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds
  debug(result)
  return result
}
503974
static String date(final long timestamp) {
    if ((timestamp & Const.SECOND_MASK) != 0) {
      return new Date(timestamp).toString();
    } else {
      return new Date(timestamp * 1000).toString();
    }
  }
380135
function dayOfWeek() {
        $num = func_num_args();
        if ($num == 3) {
            $args = func_get_args();
            $y = $args[0];
            $m = $args[1];
            $d = $args[2];
        }
        else {
            $y = $this->year;
            $m = $this->month;
            $d = $this->day;
        }
        $d += $m < 3 ? $y-- : $y - 2;
        return ((int)(23 * $m / 9) + $d + 4 + (int)($y / 4) - (int)($y / 100) + (int)($y / 400)) % 7;
    }
414099
public static function timeFriendly($timestamp = null)
    {
        if ($timestamp == null) {
            return 'N/A';
        }
        
        // 获取当前时间戳
        $currentTime = time();
        
        // 获取当天0点时间戳
        $todayZero = strtotime('today');
        
        // 获取昨天时间戳
        $yesterday = strtotime('-1 day', $todayZero);
        
        // 获取前天时间戳
        $beforeYesterday = strtotime('-1 day', $yesterday);
        
        // 获取明天0点时间戳
        $tomorrow = strtotime('+1 day', $todayZero);
        
        // 获取后天0点时间戳
        $afterTomorrow = strtotime('+1 day', $tomorrow);
        
        // 获取一天的时间戳
        $oneDayTimestamp = 3600 * 24;
        
        //当年时间戳
        $yearDiff = $currentTime - strtotime("-1 year");
        
        // 时间差
        $timeDiff = $currentTime - $timestamp;
        
        switch (true) {
            case $timestamp >= $afterTomorrow && $timestamp < $afterTomorrow + $oneDayTimestamp :
                return Yii::t('wocenter/app', 'The day after tomorrow {time}', ['time' => date('H:i', $timestamp)]);
            case $timestamp >= $tomorrow && $timestamp < $afterTomorrow :
                return Yii::t('wocenter/app', 'Tomorrow {time}', ['time' => date('H:i', $timestamp)]);
            case $timestamp >= $todayZero && $timestamp < $tomorrow :
                if ($timeDiff < (3600 * 8)) {
                    return Yii::$app->getFormatter()->asRelativeTime($timestamp);
                } else {
                    return Yii::t('wocenter/app', 'Today {time}', ['time' => date('H:i', $timestamp)]);
                }
            case $timestamp >= $yesterday && $timestamp < $todayZero :
                return Yii::t('wocenter/app', 'Yesterday {time}', ['time' => date('H:i', $timestamp)]);
            case $timestamp >= $beforeYesterday && $timestamp < $yesterday :
                return Yii::t('wocenter/app', 'The day before yesterday {time}', ['time' => date('H:i', $timestamp)]);
            default :
                if ($timeDiff > $yearDiff) {
                    return date('Y-m-d H:i', $timestamp);
                } else {
                    return date('m-d H:i', $timestamp);
                }
        }
    }
570951
public static void main(String[] args) {
		Date date = parseDate("2018/01/07 12:11:10", "yyyy/MM/dd HH:mm:ss");
		Date date2 = parseDate("2018/01/07 16:12:15", "yyyy/MM/dd HH:mm:ss");
		System.out.println(date);
		System.out.println(date2);
		System.out.println(getHoursDifference(date, date2));
	}
880366
def Timestamp(year, month, day, hour, minute, second):
    """"""
    return datetime.datetime(year, month, day, hour, minute, second)
913207
function(timeStamp) {
        var secondsPerStamp = 1.001,
            timesplit = timeStamp.split(':'),
            timestampSeconds = (parseInt(timesplit[0], 10) * 3600 +
                parseInt(timesplit[1], 10) * 60 +
                parseInt(timesplit[2], 10) +
                parseInt(timesplit[3], 10) / 30),
            seconds = timestampSeconds * secondsPerStamp,
            microSeconds = seconds * 1000 * 1000;
        return (microSeconds > 0) ? microSeconds : 0;
    }
887318
public static Integer getRemainingDayOfMonth(Date date) {

        if (date == null)
            return null;

        // 月天数
        int days = getDayNumOfMonth(date);
        // 第几天
        int dayOfMonth = getDayOfMonth(date);

        return days - dayOfMonth;
    }
978720
function DaysToNow(){ // as datetime object returns difference in seconds
		if(empty(self::$dtnow)){
			self::$dtnow=new \DateTime();
			}
		//Get difference
		$diff=$this->diff(self::$dtnow);
		$diff_days =$diff->format('%r').($diff->days);
		return $diff_days;
		}