Click here to Skip to main content
15,868,292 members
Home / Discussions / C#
   

C#

 
Questionconvert MySQL UTC_TIMESTAMP() to user local time Pin
Jassim Rahma4-Feb-14 0:13
Jassim Rahma4-Feb-14 0:13 
AnswerRe: convert MySQL UTC_TIMESTAMP() to user local time Pin
Dave Kreskowiak4-Feb-14 4:21
mveDave Kreskowiak4-Feb-14 4:21 
QuestionSense of making my own Timestamp class? Pin
Marco Bertschi3-Feb-14 20:42
protectorMarco Bertschi3-Feb-14 20:42 
AnswerRe: Sense of making my own Timestamp class? Pin
V.3-Feb-14 21:26
professionalV.3-Feb-14 21:26 
GeneralRe: Sense of making my own Timestamp class? Pin
Marco Bertschi3-Feb-14 21:35
protectorMarco Bertschi3-Feb-14 21:35 
GeneralRe: Sense of making my own Timestamp class? Pin
BillWoodruff4-Feb-14 12:43
professionalBillWoodruff4-Feb-14 12:43 
GeneralRe: Sense of making my own Timestamp class? Pin
Dave Kreskowiak4-Feb-14 13:42
mveDave Kreskowiak4-Feb-14 13:42 
AnswerRe: Sense of making my own Timestamp class? Pin
BillWoodruff4-Feb-14 3:56
professionalBillWoodruff4-Feb-14 3:56 
Marco Bertschi wrote:
Can I achieve the same with System.DateTime?
Based on the observation that all of your Properties, except milliseconds, are 'get only, I would say "yes," if you were willing to accept the limitations of inheriting from a data-structure like a Tuple<T1,T2,T3> ... given the fact that Tuple instances are immutable.

I don't claim to have thought through your use scenario here in any great depth, or to fully understand your goals here, but here's a quick sketch:
C#
using System;

namespace Feb4_2014_InheritFromTupleT1T2T3
{
    public class DateTimeEx: Tuple<DateTime, long, Int32>
    {
        private const string msPrefix = ":Z";
        private const string tzPlus = "+";

        private string tzPre;

        public DateTime dateTime { set; get; }

        public long milliSeconds { set; get; }

        public Int32 utcOffset { set; get; }

        public DateTimeEx(DateTime datetime, long millisec, Int32 utcoff) : base(datetime, millisec, utcoff)
        {
            dateTime = datetime;
            milliSeconds = millisec;
            utcOffset = utcoff;
        }

        public override string ToString()
        {
            tzPre = (milliSeconds < 0) ? "" : tzPlus;

            return string.Format("{0}-{1}-{2}T{3}:{4}:{5}.{6}Z{7}{8}", Item1.Year, Item1.Month, Item1.Day, Item1.Hour, Item1.Minute, Item1.Second, milliSeconds, tzPre, utcOffset);
        }
    }
}
Here's the results of a simple test:
DateTime rightNow = DateTime.Now;

DateTimeEx dEx1 = new DateTimeEx(rightNow, 0, 7);
DateTimeEx dEx2 = new DateTimeEx(rightNow, 0, 7);
DateTimeEx dEx3 = new DateTimeEx(rightNow, 230, 4);

Console.WriteLine(dEx1); // => 2014-2-4T21:35:19.0Z+7
Console.WriteLine(dEx3); // => 2014-2-4T21:38:1.230Z+4

Console.WriteLine(dEx1.Equals(dEx2)); // => true
Console.WriteLine(dEx1.Equals(dEx3)); // => false
I would hope what you would get from this is being able to use Parse, and ParseExact on the DateTime component, and, hopefully, save you from writing some of the overloads. But, whether you could use in the context of whatever your doing with SysLog: I ain't got a clue.

Hope this is helpful.
“But I don't want to go among mad people,” Alice remarked.

“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”

“How do you know I'm mad?” said Alice.

“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll

GeneralRe: Sense of making my own Timestamp class? Pin
Marco Bertschi4-Feb-14 4:03
protectorMarco Bertschi4-Feb-14 4:03 
AnswerRe: Sense of making my own Timestamp class? Pin
jschell4-Feb-14 13:20
jschell4-Feb-14 13:20 
GeneralRe: Sense of making my own Timestamp class? Pin
Marco Bertschi4-Feb-14 20:07
protectorMarco Bertschi4-Feb-14 20:07 
AnswerRe: Sense of making my own Timestamp class? Pin
TnTinMn6-Feb-14 12:37
TnTinMn6-Feb-14 12:37 
GeneralRe: Sense of making my own Timestamp class? Pin
Marco Bertschi6-Feb-14 21:12
protectorMarco Bertschi6-Feb-14 21:12 
GeneralRe: Sense of making my own Timestamp class? Pin
TnTinMn9-Feb-14 10:29
TnTinMn9-Feb-14 10:29 
GeneralRe: Sense of making my own Timestamp class? Pin
Marco Bertschi9-Feb-14 19:56
protectorMarco Bertschi9-Feb-14 19:56 
GeneralRe: Sense of making my own Timestamp class? Pin
TnTinMn10-Feb-14 13:12
TnTinMn10-Feb-14 13:12 
QuestionSSIS for Fixed Length line Pin
nitin_ion3-Feb-14 20:26
nitin_ion3-Feb-14 20:26 
AnswerRe: SSIS for Fixed Length line Pin
Bernhard Hiller3-Feb-14 20:52
Bernhard Hiller3-Feb-14 20:52 
GeneralRe: SSIS for Fixed Length line Pin
Marco Bertschi3-Feb-14 20:56
protectorMarco Bertschi3-Feb-14 20:56 
GeneralRe: SSIS for Fixed Length line Pin
nitin_ion3-Feb-14 21:46
nitin_ion3-Feb-14 21:46 
QuestionCreating barcode of type ean-13 in c# windows forms with sql server 2008 using StrokeScribe control of version 4.3.2 Pin
Member 102487683-Feb-14 19:00
Member 102487683-Feb-14 19:00 
SuggestionRe: Creating barcode of type ean-13 in c# windows forms with sql server 2008 using StrokeScribe control of version 4.3.2 Pin
Richard MacCutchan3-Feb-14 21:53
mveRichard MacCutchan3-Feb-14 21:53 
QuestionNorth wind Database Pin
Sandhya Bandar3-Feb-14 9:46
Sandhya Bandar3-Feb-14 9:46 
AnswerRe: North wind Database Pin
Kornfeld Eliyahu Peter3-Feb-14 9:54
professionalKornfeld Eliyahu Peter3-Feb-14 9:54 
AnswerRe: North wind Database Pin
Dave Kreskowiak3-Feb-14 12:49
mveDave Kreskowiak3-Feb-14 12:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.