javascript - Relative time function in js for format YYYY-MM-DDTHH:MM:SS+0000 -
I was wondering if anyone knew how I can parse this type of date format: 2010-07 -26 T18: 02: 46+ 0000
relative time such as "30 seconds ago"
I have a function that does the same and different time format:
function relative_time (time_value, is_relative) {var value = time_value (""), perced_data = date.pars (value [1] + "+ value [2] +", "+ value [5] ] + "" + Value [3] + "UTC"), date = new date (parsed_d T), relative_to = new date (), r = '', delta = parseint ((relative_to.getTime () - date.getTime ()) / 1000); Var seconds = {'to': {'min': function (V) {return v * 60;}, 'hours': function (v) {return.minutes (v) * 60;}, 'day': function (v) {return.hours (v) * 24; }, 'Years': function (v) {return.days (v) * 7;}, 'months': function (v) {return.weeks (v) * 4.34812141;}, 'year': function (v) {Return}}, 'To': {'min': function (v) {return v / 60;}, 'hours': function (v) {return.minutes (v) / 60; }, 'Day': function (v) {return.hours (v) / 24; }, 'Week': function (v) {return.days (v) / 7; }, 'Months': function (v) {return.weeks (v) / 4.34812141; }, 'Year': function (v) {this return. Glory (V) / 12; }}}; If (! Is_relative) returns format; date + + + datedate (date); If (Delta & Lt; 30) 'returns less than a minute ago'; Var minute = Perspective (sec.m.minets (delta) +0.5); If about (minutes & lt; = 1) 'about a minute ago'; Var hours = Perspective (seconds.Teuors (delta) +0.5); If (hours and lieutenants; 1) minute back 'minutes ago'; If (hours == 1) about 'an hour ago'; Var days = parseInt (seconds.to.days (delta) +0.5); If (day & lt; 1) return hours + 'hours ago'; If (day == 1) return format time (date) + 'tomorrow'; Var Week = Perspective (second.to.wyk (delta) +0.5); If (weeks and lie; 2) return format time (date) + '' + day + 'day ago'; Var months = persian (second; month; (delta) +0.5); If (months and lie; 2) return week + 'week ago'; Var Year = Perspective (second year (delta) +0.5); If (years and lieutenants; 2) returned months + 'months ago'; Return year + 'year ago'; Function Form TimeTime (date) {var hour = date.gethors (), minute = date. Gate Minute () + "", AMMP = 'AM'; If (bell> = 12) ampm = 'PM'; If (hours> 12) hours - = 12; If (min.length == 1) {min = '0' + min; } Return hours + ':' + min + '' + AMPM; }};
The format of this function will be: Friday 06 06:53:43 +0000
How do I change this script to work with new scripts? I have a little bit at this level and I want to learn.
Thanks
I do not know if you want to use jQuery, but :
Comments
Post a Comment