javascript两行代码按指定格式输出日期时间
javascript两行代码按指定格式输出日期时间,具体看代码:
function date2str(x,y) {
var z ={y:x.getFullYear(),M:x.getMonth()+1,d:x.getDate(),h:x.getHours(),m:x.getMinutes(),s:x.getSeconds()};
return y.replace(/(y+|M+|d+|h+|m+|s+)/g,function(v) {return ((v.length>1?"0":"")+eval('z.'+v.slice(-1))).slice(-(v.length>2?v.length:2))});
}
alert(date2str(new Date(),"yy-M-d h:m:s"));
alert(date2str(new Date(),"yyyy-MM-d h:m:s"));
javascript两行代码按指定格式输出日期时间的更多相关文章
- javascript时间戳转换成指定格式的日期
//时间戳转换成指定格式的日期DateTool.IntDatetimeTo = function(time, format){ var testDate = new Date(time); ...
- java按照指定格式输出系统时间
public class TimeFour { public static void main(String[] args) throws ParseException{ TimeFour four ...
- java按照指定格式输出系统时间使用SimpleDateFormat方法
public class TimeThree { public static void main(String[] args) { SimpleDateFormat d = new SimpleDat ...
- Week08_day01 (Hive实现按照指定格式输出每七天的消费平均数)
Hive实现按照指定格式输出每七天的消费平均数 数据准备 2018/6/1,10 2018/6/2,11 2018/6/3,11 2018/6/4,12 2018/6/5,14 2018/6/6,15 ...
- js 转换时间戳为时间格式并且按指定格式输出
/** * 时间戳转换为日期 */ function convertTimestamp(timestamp){ // 时间戳转换为日期 var d = new Date(timestamp); // ...
- YTU 2436: C++ 习题 输出日期时间--友元类
2436: C++ 习题 输出日期时间--友元类 时间限制: 1 Sec 内存限制: 128 MB 提交: 1243 解决: 690 题目描述 设计一个日期类和时间类,编写display函数用于显 ...
- YTU 2435: C++ 习题 输出日期时间--友元函数
2435: C++ 习题 输出日期时间--友元函数 时间限制: 1 Sec 内存限制: 128 MB 提交: 1069 解决: 787 题目描述 设计一个日期类和时间类,编写display函数用于 ...
- C#中 String 格式的日期时间 转为 DateTime
C#中并没有表示时间的变量,只有DateTime,所以要表示时间,可以用TimeSpan表示. 方法一:Convert.ToDateTime(string) string格式有要求,必须是yyyy-M ...
- java输出日期时间
Calendar类下方法 c.add(Calendar.YEAR,4);//加4年 c.add(Calendar.MONTH,-1);// 月份减1 c.set(2012,2,23); //把时间设置 ...
随机推荐
- ORA-27102: out of memory并伴随OSD-00031的处理
刚才客户电话过来说有个数据库起不来了,开发商搞了好久搞不掂,得要让我们去帮忙看看.过去到现场,发现数据库无法打开,连nomount模式都不可以.报错的内容大致如下: ORA-27102: out of ...
- main函数(本文较老,仅作参考)
Xcode4.2之前的main函数如下: int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePoo ...
- Python系统调用——运行其他程序
转载:http://blog.csdn.net/ssihc0/article/details/7738527 在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其 ...
- 严重: The web application [] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it.
今日在重新部署项目时出现此问题,虽然对项目无影响,但问题就是问题.完整信息如下(使用idea工具): 十二月 05, 2015 11:44:27 上午 org.apache.catalina.star ...
- Detect loop in a singly linked list
去Twitter面试的被问到这个问题,当时只想到了用HashMap的办法,这种办法时间复杂度O(n),空间复杂度是O(n), 更好的办法是用 FastRunner / SlowRunner appro ...
- uva 348
dp还是比较容易 关键是输出路径 .... #include <cstdlib> #include <cstdio> #include <cstring> #de ...
- 【图说】Eclipse与Unity 3D协同工作
原地址:http://blog.csdn.net/h570768995/article/details/9355313 Eclipse开发过程中总会碰到很多的难题,如何利用好工具帮助我们更快捷的开发也 ...
- 【leetcode】Word Ladder II(hard)★ 图 回头看
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- HDU1432+几何
题意:给N个点,求最多有多少个点在同一直线上 方法一:求出所有能形成的直线,两两比较,统计最多有多少条重合. #include<stdio.h> #include<stdlib.h& ...
- FZU-1926+KMP
题意:给定一篇文章和一些句子.询问句子是否在文章中出现. kmp模板题 /* kmp */ #include<stdio.h> #include<string.h> #incl ...