date - javascript conversion of yyyy-mm-dd hh:mm:ss aa help -


Can anyone make a mistake in this ceremony? .. It is a function that receives a string of yyyy-mm-dd hh: mm: ss A and converts to UTC and a string yyyy-mm-dd hh: mm: ss.

  Function localizedUUTC (local time) {var time = localTime.split (""); // received: - yyyy-mm-dd hh: mm: ss aa var yearday = time [0] .split ("-"); Var dateTime = time [1] .split (":"); Var ampm = time [2]; Var hour = 0; Var year = Yerde [0]; Var Finer = Yerde [1] -1; Var day = Yerde [2]; Hours = date time [0]; Var minutes = Date time [1]; Var seconds = Datetime [2]; / * We need to convert it to 24 hours format for the first time * 12:00:00 AM: 00:00:00 * 12:00:00 PM: 12:00:00 * 12 * 1:00 AM AM Even time: 1:00:00 * 1:00:00 PM: 13:00:00 * / if (PM == "PM") {// If it is 12 PM, then 12 will be causing problems (hours! = 12) {hours + = 12; }} And // am case {if (hour == 12) {hours = 00; }} Var = = new date (year, month, day, hour, minute, second); Var utcString = now.getUTCFullYear () + "-" + (Now .getCMonth () + 1) + "-" now.getUTCDate () + "+ + now .getUTCHours () +": "+ now.getUTMinutes () + ":" + Now.getUTCSeconds (); return utcString;}  

your primary The problem is that you are using strings in numerical operations, besides there are some problems in your output formatting. Here is an unwanted refactoring: -

function convertToTestring (local time) {var dateTimeComponents = LocalTime.split (""); var dateComponent = dateTimeComponents [0] .split ("-"); Var ti MeComponent = dateTimeComponents [1] .split (":") var ampm = dateTimeComponents [2] var dat = new date (persicent [0]), parseint (debt conconant [1]) -1, paracet [2]), parsat (timecompany [0])% 12, parse int (timecmant [1]), parcet (timecomponent [2]); if (ampm == "PM") // Do all locals 'AM' / 'PM'? {Dat.setHours (dat.getHours () + 12); } Function pad (val) {var s = val.toString (); Return s.length & lt; 2? "0" + s: s} return dat.getUTCFullYear () + "-" + pad ((dat.getUTCMonth (+ 1)) + "-" + pad (dat.getUTCDate ()) + "+ + Pad ( Dat.getUTCHours ()) + ":" + pad (dat.getUTCMinutes ()) + ":" + pad (dat.getUTCSeconds ());}

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -