JavaScript处理cookie和session问题已经日期问题
2018-02-27 17:01
381 查看
/**
* 2018/01/29
* 公用方法
*/
var root = "http://211.95.60.40:16868";
//var root = "http://hupes.cn";
var api = {
// 登录接口
loginApi: root + "/health/carduser",
//套餐选择页面 --快速添加受检人接口
acceptApi: root + "/health/hsubject",
// 套餐选择页面 -- 快速添加收货地址接口
acceptAddress: root + "/health/hcollect",
agreePay: root + "/health/asubs",
showExpress: root + "/health/showExpress",
onum: root + "/health/onum",
//订单信息表格
orderTable: root + "/health/showExpress",
//订单页物流信息
orderLogistics: root + "/health/onum",
// 检测报告
testReport: root + "/health/report"
}
//两个参数,一个是cookie的名子,一个是值
function SetCookie(name, value) {
var Days = 30; //此 cookie 将被保存 30 天
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days * 60 * 1000);
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
//取cookies函数
function getCookie(name) {
var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
if (arr != null) return unescape(arr[2]);
return null;
}
//删除cookie
function delCookie(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
// 日期去横杠
function toStr(str) {
return str.split('-').join('');
}
function changeDate2(val) {
var date = new Date().getTime() - (val * 24 * 60 * 60 * 1000);
var ndate = new Date(date);
var Y = ndate.getFullYear() + '-';
var M = (ndate.getMonth() + 1 < 10 ? '0' + (ndate.getMonth() + 1) : (ndate.getMonth() + 1)) + "-";
var D = (ndate.getDate() < 10 ? '0' + (ndate.getDate()) : ndate.getDate() + "");
ndate = Y + M + D;
return ndate;
}
//获取当前时间
function changeDate() {
var ndate = new Date();
var Y = ndate.getFullYear() + '-';
var M = (ndate.getMonth() + 1 < 10 ? '0' + (ndate.getMonth() + 1) : (ndate.getMonth() + 1)) + '-';
var D = (ndate.getDate() < 10 ? '0' + (ndate.getDate()) : ndate.getDate());
ndate = Y + M + D;
return ndate;
}
// 本地存储 localS
function setLocVal(key, value) {
window.localStorage[key] = value;
}
function getLocVal(key) {
if (window.localStorage[key])
return window.localStorage[key];
else
return "";
}
function delLocVal(key) {
if (window.localStorage[key])
return ""
}
// setLocVal("A",arr)
// getLocVal("A")
// 验证cookie是否过期
function loginAgain() {
var cookie = getCookie("cardid");
if (cookie == null) {
window.location.href = "nocookie.html";
}
}
// js数字转化成金额格式
function toMoney(num) {
num = num.toFixed(2);
num = parseFloat(num)
num = num.toLocaleString();
return num; //返回的是字符串23,245.12保留2位小数
}
* 2018/01/29
* 公用方法
*/
var root = "http://211.95.60.40:16868";
//var root = "http://hupes.cn";
var api = {
// 登录接口
loginApi: root + "/health/carduser",
//套餐选择页面 --快速添加受检人接口
acceptApi: root + "/health/hsubject",
// 套餐选择页面 -- 快速添加收货地址接口
acceptAddress: root + "/health/hcollect",
agreePay: root + "/health/asubs",
showExpress: root + "/health/showExpress",
onum: root + "/health/onum",
//订单信息表格
orderTable: root + "/health/showExpress",
//订单页物流信息
orderLogistics: root + "/health/onum",
// 检测报告
testReport: root + "/health/report"
}
//两个参数,一个是cookie的名子,一个是值
function SetCookie(name, value) {
var Days = 30; //此 cookie 将被保存 30 天
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days * 60 * 1000);
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
//取cookies函数
function getCookie(name) {
var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
if (arr != null) return unescape(arr[2]);
return null;
}
//删除cookie
function delCookie(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
// 日期去横杠
function toStr(str) {
return str.split('-').join('');
}
function changeDate2(val) {
var date = new Date().getTime() - (val * 24 * 60 * 60 * 1000);
var ndate = new Date(date);
var Y = ndate.getFullYear() + '-';
var M = (ndate.getMonth() + 1 < 10 ? '0' + (ndate.getMonth() + 1) : (ndate.getMonth() + 1)) + "-";
var D = (ndate.getDate() < 10 ? '0' + (ndate.getDate()) : ndate.getDate() + "");
ndate = Y + M + D;
return ndate;
}
//获取当前时间
function changeDate() {
var ndate = new Date();
var Y = ndate.getFullYear() + '-';
var M = (ndate.getMonth() + 1 < 10 ? '0' + (ndate.getMonth() + 1) : (ndate.getMonth() + 1)) + '-';
var D = (ndate.getDate() < 10 ? '0' + (ndate.getDate()) : ndate.getDate());
ndate = Y + M + D;
return ndate;
}
// 本地存储 localS
function setLocVal(key, value) {
window.localStorage[key] = value;
}
function getLocVal(key) {
if (window.localStorage[key])
return window.localStorage[key];
else
return "";
}
function delLocVal(key) {
if (window.localStorage[key])
return ""
}
// setLocVal("A",arr)
// getLocVal("A")
// 验证cookie是否过期
function loginAgain() {
var cookie = getCookie("cardid");
if (cookie == null) {
window.location.href = "nocookie.html";
}
}
// js数字转化成金额格式
function toMoney(num) {
num = num.toFixed(2);
num = parseFloat(num)
num = num.toLocaleString();
return num; //返回的是字符串23,245.12保留2位小数
}
相关文章推荐
- Javascript 日期处理之时区问题
- JavaScript中日期各种问题处理,包括常用方法和转换方法
- 关于java和javascript交互中的日期处理问题汇总
- Javascript 日期处理之时区问题
- Asp.net在ashx文件中处理Session问题
- Javascript 日期相关处理
- javascript处理HTML的Encode(转码)和Decode(解码)总结,避免js脚本注入问题
- javascript中处理时间戳为日期格式的方法
- 关于Cookie和Session的问题
- POI处理excel日期格式问题(xlsx)
- 使用ashx一般处理程序,读取不到Session的问题
- JMeter学习(二十)JMeter处理Cookie与Session
- 在一般处理文件中创建新的Session和访问已经存在的Session
- javascript日期处理
- Easyui validator.js 表单日期框校验问题黑科技处理方式
- JavaScript日期处理公共函数
- JWT 概念以及Cookie+Session解决的问题
- 关于Asp.net应用中cookie的问题处理
- 抛开Cookie使用SESSION-PHP中SESSION不能跨页传递问题的解决办法(转载)
- JavaScript读取中文cookie时的乱码问题的解决方法