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); //把时间设置 ...
随机推荐
- butterknife7.0.1使用
1.官网:http://jakewharton.github.io/butterknife/ Introduction Annotate fields with @Bind and a view ID ...
- Nginx简单性能调优
Nginx默认没有开启利用多核CPU (忍不住吐槽,然怪总感觉服务器性能没充分发挥), 我们可以通过增加worker_cpu_affinity配置参数来充分利用多核CPU.CPU是任务处理,计算最关键 ...
- PDF合并
要求:将多个table导出到一个PDF里,然后打印. 问题分析:要求将四个table放一个PDF打印,四个table的列各不相同,第一个是表头,其他三个是列表,列比表头多很多,如果直接生成一个exce ...
- 【BZOJ [1878】[SDOI2009]HH的项链
Description HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步 完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH不断地收集新的贝壳,因此, 他的项链变 ...
- submit和button提交表单的区别
<html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- 【弱省胡策】Round #5 Construct 解题报告
这个题是传说中的 Hack 狂魔 qmqmqm 出的构造题.当然要神. 这个题的本质实际上就是构造一个图,然后使得任意两点间都有长度为 $k$ 的路径相连,然后对于任意的 $i < k$,都存在 ...
- [转载]jquery ajax/post/get 传参数给 mvc的action
jquery ajax/post/get 传参数给 mvc的action 1.ActionResult Test1 2.View Test1.aspx 3.ajax page 4.MetaO ...
- openssl安装问题导致nginx添加ssl模块失败
问题:./nginx: undefined symbol: EVP_rc4_hmac_md5 sudo vi /etc/ld.so.conf #把openssl安装路径加入sudo ldconfig ...
- 【leetcode】Container With Most Water(middle)
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- Android四大基本组件
Android四大基本组件分别是 Activity:整个应用程序的门面,负责与用户进行交互. Service:承担大部分工作. Content Provider内容提供者:负责对外提供数据,并允许需要 ...