(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. String中的toCharArray:将此字符串转换为新的字符数组,并统计次数

    package stringyiwen; public class StringTestToCharArray { public static void main(String[] args) { S ...

  2. 如何重置mate的面板到初始化时的默认设置?

    在你的任何终端中敲入如下命令: gsettings reset-recursively org.mate.panel

  3. HDU 3746 将字符串的全部字符最少循环2次需要添加的字符数

    Sample Input3aaaabcaabcde Sample Output025 题目大意:给你一个字符串,要求将字符串的全部字符最少循环2次需要添加的字符数.例子:abcabc 已经循环2次,添 ...

  4. python 防死锁机制

    https://www.cnblogs.com/wongbingming/p/9035575.html ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 在编写多线程程序时,可能无意中就会写 ...

  5. spring配置redis注解缓存

    前几天在spring整合Redis的时候使用了手动的方式,也就是可以手动的向redis添加缓存与清除缓存,参考:http://www.cnblogs.com/qlqwjy/p/8562703.html ...

  6. URAL - 1078 Segments

    URAL - 1078 题目大意:有n条线段,一个线段a 完全覆盖另一个线段b 当且仅当,a.l < b.l && a.r>b.r.问你 一个线段覆盖一个线段再覆盖一个线段 ...

  7. 【Java】 剑指offer(18) 删除链表中重复的结点

    本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集   题目 在一个排序的链表中,如何删除重复的结点?例如,在图3.4(a)中重 ...

  8. HDU.2516.取石子游戏(博弈论 Fibonacci Nim)

    题目链接 \(Description\) 1堆石子有n个.两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍,取完者胜.问谁能赢. \(Solution ...

  9. Python中的MySQLConnector使用介绍

    MySQL Connector/Python 是 MySQL 官方提供的 Python 连接 MySQL 数据库的驱动程序了,很多初学者对于 在python中连接mysql数据库还是有点为难了,下文我 ...

  10. 阿里P6大牛给予Java初学者的学习路线建议

    Java学习这一部分是今天的重点,这一部分用来回答很多群里的朋友所问过的问题,那就是你是如何学习Java的,能不能给点建议?今天我是打算来点干货,因此咱们就不说一些学习方法和技巧了,直接来谈每个阶段要 ...