baavgai's Profile User Rating: *****

Reputation: 5805 Overlord
Group:
Mentors
Active Posts:
12,645 (5.03 per day)
Joined:
16-October 07
Profile Views:
121,864
Last Active:
User is offline Today, 12:41 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
725
Expert In:
C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Latest Visitors

Icon   baavgai has not set their status

Posts I've Made

  1. In Topic: Convert from datetime to unix time

    Posted 2 Sep 2014

    Again, you need to analyze what you're seeing. Just because the default format doesn't bother with ms, doesn't mean you can't print it.

    Given a format:
    WriteLine("DateTime  = " + dt.ToString("MM/dd/yyyy hh:mm:ss.fff tt"));
    
    


    You get:
    UNIX Time = 1300123800440
    DateTime  = 03/14/2011 05:30:00.440 PM
    ------------------------------
    Parse String = 03/14/2011 05:30 PM
    UNIX Time = 1300123800000
    DateTime  = 03/14/2011 05:30:00.000 PM
    ------------------------------
    
    
  2. In Topic: Convert from datetime to unix time

    Posted 1 Sep 2014

    Perhaps if you used PM, rather than AM? Print the date. Confirm that it is what you think it is.
  3. In Topic: Convert from datetime to unix time

    Posted 1 Sep 2014

    There a numerous formats that Convert.ToDateTime will work with. However, if you choose one that's not generally used on planet Earth...

    You can describe your custom format for the parser, explained here: http://msdn.microsof...=vs.110%29.aspx

    Your could also is to reformat your string to match something standard.

    Good luck.
  4. In Topic: Convert from datetime to unix time

    Posted 1 Sep 2014

    View Postnighttrain, on 01 September 2014 - 07:57 AM, said:

    what should be fixed here baavgai i really dont know after checking diffrent modification cant make it valid.


    Um, you wrote it.

    I'd say only accept milliseconds and go from there. With this in mind, only accept long, as Unix time has not decimals.

    e.g.
    static class UnixTime {
      private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
      private static readonly long MaxUnixSeconds = (long)((DateTime.MaxValue - UnixEpoch).TotalSeconds);
      private const double LongAdj = 1000.0;
      public static DateTime ToDateTime(long unixTimeStamp) { return UnixEpoch.AddSeconds(unixTimeStamp / LongAdj); }
      public static long FromDateTime(DateTime date) { return (long)((date - UnixEpoch).TotalSeconds * LongAdj); }
    
      public static void Test(long n) {
        System.Diagnostics.Debug.WriteLine("UNIX Time = " + n);
          var dt = ToDateTime(n);
          System.Diagnostics.Debug.WriteLine("DateTime = " + dt);
          var fromDt = FromDateTime(dt);
          System.Diagnostics.Debug.WriteLine("UNIX Time = " + fromDt);
          System.Diagnostics.Debug.WriteLine("IsGood = " + (n==fromDt));
        }
    
      public static void Test() { Test(1300123800440); }
    }
    
    


    Results of test:
    UNIX Time = 1300123800440
    DateTime = 3/14/2011 5:30:00 PM
    UNIX Time = 1300123800440
    IsGood = True
    
    
  5. In Topic: Convert from datetime to unix time

    Posted 1 Sep 2014

    What do ticks have to do with anything?

    Perhaps:
    public static double UnixTimestampFromDateTime(DateTime date)
        return (date - UnixEpoch).TotalSeconds;
    }
    
    


    Recall, you passed a double before. Be consistent.

    Note, your solution seems valid, considering the odd second or millisecond manipulation you do with the first conversion. Again, be consistent.

My Information

Member Title:
Dreaming Coder
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Jersey, be afraid.
Years Programming:
25
Programming Languages:
Most.

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://

Comments

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  1. Photo

    8byte Icon

    10 Jan 2014 - 11:08
    Awesome, thanks for all the help!
  2. Photo

    codiddle Icon

    07 Mar 2013 - 18:59
    GENIUS GUY HERE MAN. Write a book!
  3. Photo

    mamelove25 Icon

    19 Feb 2013 - 10:53
    Hello My Dear, My Name is Mame. i saw your profile today and became interested in you,i will also like to know you more,and if you can send an email to my email address,i will give you my pictures here is my email address (mame25live@yahoo.co.uk) I believe we can move from here! Am waiting for your mail to my email address above because i have much to tell you,
    love Miss Mame.
  4. Photo

    bilbil0629 Icon

    24 Oct 2012 - 05:39
    hey! you mongolian?
  5. Photo

    Ticon Icon

    20 Aug 2012 - 13:23
    I just noticed your an expert in cheese. I lol'd
  6. Photo

    mostyfriedman Icon

    18 Aug 2012 - 23:13
    Hello there Brett
  7. Photo

    MehrdadSecret Icon

    26 Jul 2012 - 05:51
    hello, can i have a contact email or Yahoo or something? Need ur help badly
  8. Photo

    Jeet.in Icon

    18 Apr 2012 - 23:17
    Thanks ! Solved My problem !
    http://www.dreamincode.net/forums/topic/275578-simple-whitespace-remover/page__gopid__1603556&#entry1603556
  9. Photo

    RetardedGenius Icon

    25 Oct 2011 - 14:29
    I agree so much with your opinion of incompetent CS teachers. So true!
    http://www.dreamincode.net/forums/topic/252848-venting-a-frustration/page__view__findpost__p__1469659
  10. Photo

    WabiSabi Icon

    21 Oct 2011 - 11:00
    I agree with assert(C). However, I'd rather not specify what you are "the best" at.
  11. Photo

    assert(C) Icon

    20 Oct 2011 - 08:38
    You are the best
  12. Photo

    macosxnerd101 Icon

    30 Sep 2011 - 09:33
    Congrats on hitting the big 3k!
  13. Photo

    sjin Icon

    16 Aug 2011 - 18:41
    This guy is AWESOME! Cheers bro!
  14. Photo

    hulla Icon

    02 Aug 2011 - 02:50
    Wow that's alot of programming languages... :O
  15. Photo

    Aphex19 Icon

    04 Jul 2011 - 16:54
    Kudos to you baavgai, the most well deserved mentor on DIC in my opinion.
  • (3 Pages)
  • +
  • 1
  • 2
  • 3