andrew4582

DateTimeHelper

Sep 6th, 2010
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Core {
  7.  
  8.     public static class DateTimeHelper {
  9.         public static DateTime NextMonth(DateTime d) {
  10.             return d.AddMonths(1);
  11.         }
  12.         public static DateTime FirstDayOfMonth(DateTime d) {
  13.             return DateTime.Parse("{0}/1/{1}".FormatString(d.Month,d.Year));
  14.         }
  15.         public static DateTime LastDayOfMonth(DateTime d) {
  16.             return FirstDayOfMonth(d).AddMonths(1).AddDays(-1);
  17.         }
  18.         public static DateTime ConvertFromUnixTimestamp(double timestamp) {
  19.             DateTime origin = new DateTime(1970,1,1,0,0,0,0);
  20.             return origin.AddSeconds(timestamp);
  21.         }
  22.         public static double ConvertToUnixTimestamp(DateTime date) {
  23.             DateTime origin = new DateTime(1970,1,1,0,0,0,0);
  24.             TimeSpan diff = date - origin;
  25.             return Math.Floor(diff.TotalSeconds);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment