コード例 #1
0
        public void TestNonEnglishSMTPDate()
        {
            CultureInfo japanese = new CultureInfo("ja-JP");

            System.Threading.Thread.CurrentThread.CurrentCulture = japanese;

            TimeZone timezone = TimeZone.CurrentTimeZone;

            DateTime datetime  = new DateTime(2005, 2, 8, 9, 34, 56);
            String   tzhours   = String.Format("{0:00}", timezone.GetUtcOffset(datetime).Hours);
            String   tzminutes = String.Format("{0:00}", timezone.GetUtcOffset(datetime).Minutes);
            String   tzstring  = tzhours + tzminutes;

            if (timezone.GetUtcOffset(datetime).Hours >= 0)
            {
                tzstring = "+" + tzstring;
            }
            RFC2822Date rfcdate = new RFC2822Date(datetime, timezone);

            Assert.AreEqual("Tue, 8 Feb 2005 09:34:56 " + tzstring, rfcdate.ToString());

            datetime = new DateTime(2005, 2, 8, 19, 34, 56);
            rfcdate  = new RFC2822Date(datetime, timezone);
            Assert.AreEqual("Tue, 8 Feb 2005 19:34:56 " + tzstring, rfcdate.ToString());
        }
コード例 #2
0
        public void TestSMTPDate()
        {
            TimeZone timezone = TimeZone.CurrentTimeZone;

            DateTime datetime  = new DateTime(2005, 2, 8, 9, 34, 56);
            String   tzhours   = String.Format("{0:00}", timezone.GetUtcOffset(datetime).Hours);
            String   tzminutes = String.Format("{0:00}", timezone.GetUtcOffset(datetime).Minutes);
            String   tzstring  = tzhours + tzminutes;

            if (timezone.GetUtcOffset(datetime).Hours >= 0)
            {
                tzstring = "+" + tzstring;
            }
            RFC2822Date rfcdate = new RFC2822Date(datetime, timezone);

            Assert.AreEqual("Tue, 8 Feb 2005 09:34:56 " + tzstring, rfcdate.ToString());

            datetime = new DateTime(2005, 2, 8, 19, 34, 56);
            rfcdate  = new RFC2822Date(datetime, timezone);
            Assert.AreEqual("Tue, 8 Feb 2005 19:34:56 " + tzstring, rfcdate.ToString());
        }