Is there a php date () method in Javascript-js?

Source: Internet
Author: User
Title, want to implement the function.
Incoming timestamp "1400000000", return format: 2015-01-01

PHP Implementation: Date ("Y-m-d h:i:s", "1400000000");
JavaScript implementation??

Reply content:

Title, want to implement the function.
Incoming timestamp "1400000000", return format: 2015-01-01

PHP Implementation: Date ("Y-m-d h:i:s", "1400000000");
JavaScript implementation??

It is easy to achieve a bit, write a rough, but can achieve

function getFormatDate(split,timeInMs){  var curr=new Date();  curr.setTime(timeInMs);  var year=curr.getFullYear();  var month=curr.getMonth()+1;  var date=curr.getDate();    var hours=curr.getHours();  var minutes=curr.getMinutes();  var seconds=curr.getSeconds();    var formatDateStr=year+split[0]+month+split[0]+date+" "+hours+split[1]+minutes+split[1]+seconds;  return formatDateStr;}var res=getFormatDate(["-",":"],1433456000345); //这里要输入13位数console.log(res); // 2015-6-5 6:13:20

Https://github.com/jacwright/date.format

The realization of their own can see the above several, I put a plug-in.

http://momentjs.cn/

Compatible with most PHP implementations of the DATE function:

function Date () {if (arguments.length = = 0) {throw "date () expects at least 1 parameter, 0 given";    } var format = arguments[0]; var time = arguments.length > 1?    New Date (arguments[1] *): new date ();    var padding = function (str, length) {return "0000". substr (0, length-str.tostring (). length) + str; } return Format.replace (/[a-z]/ig, function (c) {var dayofyear = function (time) {return (Time.getti        Me ()-(New Date (Time.getfullyear (), 0, 1)). GetTime ())/86400000 >> 0;            } var daysofmonth = function (time) {var year = time.getfullyear ();            var month = Time.getmonth ();        Return (new date (year, month + 1, 1)). GetTime ()-(new date (year, month, 1)). GetTime ())/86400000 >> 0; } var sign = function (num) {return num >= 0?        "+" : "-";            } switch (c) {case "D": Return padding (time.getdate ()); CaSe "D": Return ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][time.getday ()];            Case "J": Return Time.getdate (); Case "L": return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][time.getday            ()];            Case "N": Return [7, 1, 2, 3, 4, 5, 6][time.getday ()];                    Case ' S ': Switch (time.getdate ()) {case 1:return "st";                    Case 2:case 22:return "nd";                Case 3:case 23:return "RD";            } return "th";            Case "W": Return Time.getday ();            Case "Z": Return DayOfYear (Time);            Case "W": Return DayOfYear (Time)/7 >> 0; Case "F": Return ["January", "February", "March", "April""May", "June", "July", "August", "September", "October", "November", "December"][time.getmonth ()];            Case "M": Return padding (time.getmonth () + 1, 2); Case ' M ': return ["Jan", "Feb", "Mar", "APR", "may", "June", "Jul", "][time", "Sep", "Oct", "Nov", "Dec".            GetMonth ()];            Case "n": Return Time.getmonth () + 1;            Case "T": return Daysofmonth (Time);            Case "L": Return DayOfYear (New Date (Time.getfullyear () + 1, 0, 1)) = = 365;            Case "Y": Return Time.getfullyear ();            Case "Y": Return padding (time.getfullyear ()% 100, 2); Case "A": Return Time.gethours () >= 12?            "AM": "PM"; Case "A": Return time.gethours () >= 12?            "AM": "PM";            Case "G": return Time.gethours ()% 12;            Case "G": Return Time.gethours (); CasE "h": Return padding (time.gethours ()% 12, 2);            Case "H": Return padding (Time.gethours (), 2);            Case "I": Return padding (Time.getminutes (), 2);            Case "s": Return padding (Time.getseconds (), 2);            Case "U": return Time.gettime ()% 1000 + "000"; Case ' O ': Return sign (-time.gettimezoneoffset ()) + padding (Math.Abs (Time.gettimezoneoffset ())/60, 2) + "0            0 ";  Case ' P ': Return sign (-time.gettimezoneoffset ()) + padding (Math.Abs (Time.gettimezoneoffset ())/>>            0, 2) + ":" + Math.Abs (time.gettimezoneoffset ())% 60;            Case "Z": Return-time.gettimezoneoffset ();            Case "U": Return Time.gettime ()/>> 0;            Case ' O ': Case ' B ': Case ' e ': Case ' I ': Case ' T ': Case ' C ': Case "R": Throw C+ "is not yet implemented.";         Default:return C; }    })}

 //extension to date, string//months (m), days (d), hours (h), minutes (m), seconds (s), quarter (Q) of date converted to the specified format can be used 1-2 placeholders,//year (Y) can be used with 1-4 placeholders, milliseconds (S) can only be used with 1 placeholders (1-3 digits) function formatdate (date, FMT) {//author:meizz FMT = FMT | |    ' Yyyy-mm-dd hh:mm:ss ';        var o = {"m+": Date.getmonth () +1,//month "d+": date.getdate (),//day "H +": date.gethours (),//Hour "m+": date.getminutes (),//Sub-"s+": date.g Etseconds (),//sec "q+": Math.floor ((Date.getmonth () +3)/3),//Quarterly "S": Date.getmilliseconds (    )//milliseconds};    if (/(y+)/.test (FMT)) Fmt=fmt.replace (Regexp.$1, (date.getfullyear () + ""). substr (4-regexp.$1.length));  For (var k in O) if (New RegExp ("(" + K + ")"). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length==1) ?    (O[k]): (("XX" + o[k]). substr (("" + O[k]).)); return FMT;}  

Don't thank me, I copied it from somewhere else.

var unixTimestamp = new Date(1446027232 * 1000);commonTime = unixTimestamp.toLocaleString();

I hope this will help you a little.

Yes, but it's not very useful.
Also available in other languages

Java    timeJavaScript    Math.round(new Date().getTime()/1000)getTime()返回数值的单位是毫秒Microsoft .NET / C#    epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000MySQL    SELECT unix_timestamp(now())Perl    timePHP    time()PostgreSQL    SELECT extract(epoch FROM now())Python    先 import time 然后 time.time()Ruby    获取Unix时间戳:Time.now 或 Time.new显示Unix时间戳:Time.now.to_iSQL Server    SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())Unix / Linux    date +%sVBScript / ASP    DateDiff("s", "01/01/1970 00:00:00", Now())其他操作系统(如果Perl被安装在系统中)    命令行状态:perl -e "print time"

It is recommended to use Momentjs, the chance of a bug is small, but there is time to study the extensions that you wrote upstairs.

Https://segmentfault.com/q/1010000000701472/a-1020000005044252?utm_source=Weibo
Upstairs code is good, here also has one, similar.

function formatDate(now)   {                   var   year=now.getYear();                   var   month=now.getMonth()+1;                   var   date=now.getDate();                   var   hour=now.getHours();                   var   minute=now.getMinutes();                   var   second=now.getSeconds();                   return   year+"-"+month+"-"+date+"   "+hour+":"+minute+":"+second;      

You can try this function.
You can change this.
return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;

sdfsdfsd

sdfsadfsd
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.