อันนี้ของติ๊กก๊าบ เป็นcode vb.net
หารับค่าวันเวลามาเป็นสตริง แล้วหาว่าผ่านมาแล้วเป็นเวลาเท่าไหร่ กี่วัน กี่เดือน กี่ปี
ตัวอย่างเวลาที่รับมาต้องมีformat (yyyy/mm/dd)
ได้เวลามาแล้วก็แปลงให้เป็นชนิดข้อมูลแบบวันที่ แล้วนำมาลบกับเวลาปัจจุบัน โดยใช้ DateInterval.Day เพื่อลบให้ได้เป็นจำนวนวันออกมา
Protected Function FindTime(ByVal time As Date) As String Dim tmp As String = String.Empty Dim today As Date = Date.Now 'Dim today As Date = Date.Parse("2553/01/06") Dim result As Integer = Convert.ToInt32( DateDiff(DateInterval.Day,time.Date,today.Date)) If Convert.ToInt32(result / 356) > 0 Then tmp = Convert.ToInt32(result / 356) &" year" & IIf(Convert.ToInt32(result / 356) > 1,"s","") & " ago" ElseIf Convert.ToInt32(result / 30) > 0 Then tmp = Convert.ToInt32(result / 30) &" monuth" & IIf(Convert.ToInt32(result / 30)>1,"s","") & " ago" ElseIf today.Date = time.Date tmp = "today" ElseIf result <> 0 Then tmp = today.Day - time.Day & " day" & IIf(today.Day - time.Day > 1, "s", "") & " ago" End If Return tmp End Function
อันนี้ของพี่กบ ละเอียดก่าเยอะก๊าบ เป็น c# รับค่าเป็น datetime แล้วรีเทิร์นค่าเป็นสตริง บอกได้ในระดับวินาทีก๊าบ เอิ๊กเอิ๊กเอิ๊ก ละเอียดดีก๊าบ
public static string ToTimeSinceString(DateTime value) { const int SECOND = 1; const int MINUTE = 60 * SECOND; const int HOUR = 60 * MINUTE; const int DAY = 24 * HOUR; const int MONTH = 30 * DAY; TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - value.Ticks); double seconds = ts.TotalSeconds; // เลือกเวลาทั้งหมดที่ลบได้มาเป็นวินาทีเ พื่อไปคำนวณหาว่าผ่านมาเท่าไหร่แล้ว นับตั้งแต่วินาทีเป็นต้นไป if (seconds < 1 * MINUTE) return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago"; if (seconds < 60 * MINUTE) return ts.Minutes <= 1 ? "one minute ago" : ts.Days + " minutes ago"; if (seconds < 120 * MINUTE) return "an hour ago"; if (seconds < 24 * HOUR) return ts.Hours <= 1 ? "one hour ago" : ts.Days + " hours ago"; if (seconds < 48 * HOUR) return "yesterday"; if (seconds < 30 * DAY) if (ts.Days >= 7) { double days = Math.Ceiling((double)ts.Days / 7); return days <= 1 ? "one week ago" : days + " weeks ago"; } else { return ts.Days <= 1 ? "one day ago" : ts.Days + " days ago"; } // end } if (seconds < 12 * MONTH) { int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30)); return months <= 1 ? "one month ago" : months + " months ago"; } // end int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365)); return years <= 1 ? "one year ago" : years + " years ago"; } // end
เพื่อนสามารถเลือกเอาไปปรับใช้กันได้นะก๊าบ^^
Medicamentspot.com International Legal RX Medications. Special Internet Prices (up to 40% off average US price). NO PRIOR PRESCRIPTION REQUIRED!…
Combivir@buy.online” rel=”nofollow”>.…
PillSpot.org. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices(up to 40% off average US price).PillSpot.org. Vitamins@buy.online” rel=”nofollow”>.…
Categories: Cholesterol.Weight Loss.Stop SmokingAntidepressants.Mental Health/Epilepsy.Anxiety/Sleep Aid.Stomach.Pain Relief.Antibiotics.Mens Health.Vitamins/Herbal Supplements.Antiviral.General Health.Skin Care.Womens Health.Antidiabetic.Blood Pr…
Buy:Propecia.Viagra Professional.Cialis Super Active+.Zithromax.Viagra Super Force.Cialis Soft Tabs.Maxaman.Cialis Professional.Tramadol.Viagra Super Active+.Levitra.Viagra Soft Tabs.Super Active ED Pack.Soma.Cialis.Viagra.VPXL….
80 Tractor allis light/ http://ANTIQUEFURNINISHING.INFO/tag/1 : 1…
80 Tractor allis light/…
Adjustable http://urackuvjfr6.AWESOMEBABYCLOTHES.INFO/tag/Adjustable+puck+Puck/ : puck…
Adjustable…
driver http://tfinddp.AUTOSECTIONS.INFO/tag/R2-D2+driver+v12/ : R2-D2…
driver…