(function ($) {
$.extend({
myTime: {
/**
* 当前时间戳
* @return <int> unix时间戳(秒)
*/
CurTime: function () {
return Date.parse(new Date()) / 1000;
},
/**
* 日期 转换为 Unix时间戳
* @param <string> 2014-01-01 20:20:20 日期格式
* @return <int> unix时间戳(秒)
*/
DateToUnix: function (string) {
var f = string.split(' ', 2);
var d = (f[0] ? f[0] : '').split('-', 3);
var t = (f[1] ? f[1] : '').split(':', 3);
return (new Date(
parseInt(d[0], 10) || null,
(parseInt(d[1], 10) || 1) - 1,
parseInt(d[2], 10) || null,
parseInt(t[0], 10) || null,
parseInt(t[1], 10) || null,
parseInt(t[2], 10) || null
)).getTime() / 1000;
},
/**
* 时间戳转换日期
* @param <int> unixTime 待时间戳(秒)
* @param <bool> isFull 返回完整时间(Y-m-d 或者 Y-m-d H:i:s)
* @param <int> timeZone 时区
*/
UnixToDate: function (unixTime, isFull, timeZone) {
if (typeof (timeZone) == 'number') {
unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
}
var time = new Date(unixTime * 1000);
var ymdhis = "";
ymdhis += time.getUTCFullYear() + "-";
ymdhis += (time.getUTCMonth() + 1) + "-";
ymdhis += time.getUTCDate();
if (isFull === true) {
ymdhis += " " + time.getUTCHours() + ":";
ymdhis += time.getUTCMinutes() + ":";
ymdhis += time.getUTCSeconds();
}
return ymdhis;
}
}
});
})(jQuery);

Jquery实现日期转换为 Unix时间戳及时间戳转换日期的更多相关文章

  1. php时间戳和日期转换,以及时间戳和星期转换

    $this->created_at为时间戳值,转换日期如下 date('m.d',$this->created_at) :  y 代表年的后两位如 17 ,Y 代表 2017  , m 代 ...

  2. [工具类]将时间转换为unix时间戳格式

    写在前面 由于在数据库中存的时间有时间戳格式的数据,在解析以及保存的时候,就需要考虑到数据格式的兼容性问题.看到数据库中的时间字段基本上都是以时间戳格式存储的,没办法,只能将时间进行转换了,考虑到其他 ...

  3. C# DateTime时间格式转换为Unix时间戳格式

    double ntime=dateTimeToUnixTimestamp(DateTime.Now); long g1 = GetUnixTimestamp(); long g2 = ConvertD ...

  4. mysql语句将日期转换为时间戳的方法

    mysql将日期转换为时间戳更新数据库: update test set creattime=UNIX_TIMESTAMP('2018-04-19') 替换字段为当前日期: update test s ...

  5. DateTime时间格式转换为Unix时间戳格式

    /// <summary> /// 将DateTime时间格式转换为Unix时间戳格式 /// </summary> /// <param name="date ...

  6. c# dateTime格式转换为Unix时间戳工具类

    using System; using System.Collections.Generic; using System.Text; namespace TJCFinanceWriteOff.BizL ...

  7. android: 日期转Unix时间戳,Unix时间戳转日期,带时区

    1.UTC时间&GMT时间 UTC时间是时间标准时间(Universal Time Coordinated),UTC是根据原子钟来计算时间,误差非常小. UTC也是指零时区的时间,如果要表示其 ...

  8. mysql 日期操作 增减天数、时间转换、时间戳(转)

    转自http://www.cnblogs.com/wenzichiqingwa/archive/2013/03/05/2944485.html http://hi.baidu.com/juntao_l ...

  9. mysql 日期操作 增减天数、时间转换、时间戳(转换)

    http://hi.baidu.com/juntao_li/item/094d78c6ce1aa060f6c95d0b MySQL datediff(date1,date2):两个日期相减 date1 ...

随机推荐

  1. FakeImageExploiter v1.3

    FakeImageExploiter v1.3 - backdoor images.jpg[.ps1] CodeName: Metamorphosis Version release: v1.3 (S ...

  2. ERP采购业务(三十七)

    产品构建表的添加存储过程: CREATE PROCEDURE [dbo].[BioPurchaseAppInfo_ADD] @PurchaseID INT OUTPUT, @Subject NVARC ...

  3. JSON.NET 空值处理, 数字转字符,时间格式化

    public static string ToJsonString(this Object obj) { IsoDateTimeConverter idtc = new IsoDateTimeConv ...

  4. 用SQL统计每分钟的访问量

    以前面试没有理解到它什么意思的一道题,回忆中是这个题意 ), to_char(r.datelastmaint, 'yyyy-mm-dd hh24:mi'), sum(abs(r.tranamt)) f ...

  5. PKUWC2019游记&&WC2019游记

    今天好颓,不想写代码了,写写游记 PKUWC2019游记&&WC2019游记 PKUWC2019游记 提前两天就来了中山纪中,考了两天模拟,第一天比较正常,但是可做题只有T3,第二天非 ...

  6. Redis中的key的通用操作

    1.看看所有的key 2.查看以mys开头的key 3.是否存在 4.删除 5.重命名. 6.设置过期时间与所剩的时间 如果没有设置,返回-1. 7.返回类型

  7. 052 自动将每日的日志增量导入到hive中

    一:大纲介绍 1.导入方式 load data local inpath 'local_file_path' into table tbname partition (date='',hour='') ...

  8. C# 反编译破解软件方法

    我们有时在使用一些小工具软件时,会提示购买License(注册码之类的东东)后才能正常使用.在这里我们来尝试直接绕过License验证直接使用软件,实现简单的软件破解. 主要实现方式: 通过反编译工具 ...

  9. Unicode字符编码表(转)

    Unicode字符编码表     版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/zhenyu5211314/article/details/5153 ...

  10. docker使用dockerfile 构建redis镜像

    FROM redis WORKDIR /data VOLUME /data EXPOSE RUN echo "success---------success" ENTRYPOINT ...