public  enum DateInterval
{
    Second, Minute, Hour, Day, Week, Month, Quarter, Year
}

public sealed class DateTimeManger
{

    private DateTimeManger()
    {}//end of default constructor

    public static long DateDiff(DateInterval Interval, System.DateTime StartDate,    System.DateTime EndDate )
    {
        long lngDateDiffValue = 0;
        System.TimeSpan TS = new System.TimeSpan(EndDate.Ticks - StartDate.Ticks);
        switch (Interval)
        {
            case DateInterval.Second:
            lngDateDiffValue = (long) TS.TotalSeconds;
            break;
            case DateInterval.Minute:
            lngDateDiffValue = (long) TS.TotalMinutes;
            break;
            case DateInterval.Hour:
            lngDateDiffValue = (long)TS.TotalHours;
            break;                                   
            case DateInterval.Day:
            lngDateDiffValue = (long) TS.Days;
            break;
            case DateInterval.Week:
            lngDateDiffValue = (long)( TS.Days / 7);
            break;
            case DateInterval.Month:
            lngDateDiffValue = (long)( TS.Days / 30);
            break;
            case DateInterval.Quarter:
            lngDateDiffValue = (long)( (TS.Days / 30) / 3 );
            break;
            case DateInterval.Year:
            lngDateDiffValue = (long)( TS.Days / 365);
            break;
        }
        return (lngDateDiffValue);
    }//end of DateDiff

}//end of class


Samples:
public class DateDiffCS
{
    public static void Main (string[] CmdLineArgs)
    {
        System.DateTime date1 = System.DateTime.Now;
        System.DateTime date2 = System.DateTime.Now.AddYears(2);

        System.Console.Out.WriteLine("Days : " + DateTimeManger.DateDiff
        (DateTimeManger.DateInterval.Day,date1,date2).ToString());
        System.Console.Out.WriteLine("Hours : " + DateTimeManger.DateDiff
        (DateTimeManger.DateInterval.Hour,date1,date2).ToString());
        System.Console.Out.WriteLine("Minutes : " + DateTimeManger.DateDiff
        (DateTimeManger.DateInterval.Minute,date1,date2).ToString());
        System.Console.Out.WriteLine("Month : " + DateTimeManger.DateDiff
        (DateTimeManger.DateInterval.Month,date1,date2).ToString());
        System.Console.Out.WriteLine("Quarter : " + DateTimeManger.DateDiff
        (DateTimeManger.DateInterval.Quarter,date1,date2).ToString());
        System.Console.Out.WriteLine("Seconds : " + DateTimeManger.DateDiff
        (DateTimeManger.DateInterval.Second,date1,date2).ToString());
        System.Console.Out.WriteLine("Week : " + DateTimeManger.DateDiff
        (DateTimeManger.DateInterval.Week,date1,date2).ToString());
        System.Console.Out.WriteLine("Year : " + DateTimeManger.DateDiff
        (DateTimeManger.DateInterval.Year,date1,date2).ToString());

        System.Console.In.ReadLine();

    }

}//end of the class

posted @ 2006-07-28 10:26 幸运儿 阅读(192) 评论(1) 编辑

C# Open Source

Open Source Aspect-Oriented Frameworks in C#

  • AspectSharp - Aspect# (pronunced as AspectSharp) is a free AOP ( Aspect Oriented Programming ) framework for the .NET Framework, it uses Dynamic Proxies and XML configuration files as basis.

Open Source Bloggers in C#

  • tBlogger - tBlogger provides a complete blog site written in C# with ASP.NET that uses XML as a backend.

Open Source Build Systems in C#

  • NAnt - NAnt is a Ant like build tool for .NET

Open Source Charting & Reporting Tools in C#

  • NChart - NChart provides a wealth of 2D charting for use in business, in education and at home.

Open Source Chat Servers in C#

Open Source Content Management Systems (CMS) in C#

  • ndCMS - ndCMS is a content management system written in C# that features a user manager, file manager, a WYSIWYG editor and built-in http compression (for those who are not running at least IIS 6 and/or don't have access to modify your IIS settings directly and/or those who don't want to spend a small fortune on a third party HTTP Compressor). The goal of ndCMS is to provide a quick and easy way to deploy a .net website while saving you time and money.

Open Source Code Coverage Tools in C#

  • NCover - A test code coverage tool for C# .NET

Open Source Forum Software in C#

  • YetAnotherForum - Yet Another Forum.net is a opensource discussion forum or bulletin board system for web sites running ASP.NET. It is ASP.NET based with a MS SQL backend database.

Open Source IDEs in C#

  • SharpDevelop - #develop (short for SharpDevelop) is a free IDE for C# and VB.NET projects on Microsoft's .NET platform.

Open Source Installers Generators in C#

  • NInstall - A project to produce an open source package that can compete with the commercial installer products

Open Source Inversion of Control Containers in C#

  • StructureMap - StructureMap is a lightweight Inversion of Control (IoC) Container written in C# for .NET development. StructureMap can improve the architectural qualities of an object oriented .NET system by reducing the mechanical costs of good design techniques.

Open Source Issue Tracking Software in C#

  • BugBye - BugBye is a web-based bugtracking system developed using ASP.NET technology and C# as scripting language

Open Source Logging Tools in C#

  • log4net - log4net is a tool to help the programmer output log statements to a variety of output targets. log4net is a port of the excellent log4j framework to the .NET runtime.

Open Source Network Clients in C#

  • OpenSmtp.net - OpenSmtp.net is an open source SMTP component written in C#

Open Source Network Servers in C#

  • CSharp Email Server - The C# Mail Server is a C# port of the Java Email Server (JES). JES is an established email server targeted at small centrally maintained installations.

Open Source PDF Libraries in C#

  • iTextSharp - iTextSharp is a library that allows you to generate PDF files on the fly.

Open Source Persistence Frameworks in C#

  • OJB.NET - OJB.NET is an object-to-relational persistence tool for the .NET platform.

Open Source Portals in C#

  • OmniPortal - OmniPortal was built on the idea of having a web-portal-kernel, that could handle security, themeing, and localization.

Open Source Profilers in C#

  • NProfiler - An application profiler for .NET

Open Source Project Management Tools in C#

  • User Story.NET - This project is a tool for Extreme Programming projects in their User Story tracking.

Open Source RSS & RDF Tools in C#

  • RSS Bandit - A desktop news aggregator written in C#

Open Source Rule Engines in C#

  • NxBRE - NxBRE is the first open-source rule engine for the .NET platform and a lightweight Business Rules Engine (aka Rule-Based Engine)

Open Source Search Engines in C#

  • Lucene.Net - Lucene.Net is a complete up to date .NET port of Jackarta Lucene

Source Control Tools in C#

  • NetCvsLib - NetCvsLib is a CVS client written entirely in C# for the .NET platform. It is implemented as an assembly, and thus can easily be incorporated into other projects.

Open Source SQL Clients in C#

  • Database Commander - Database Commander is a database manager with user-friendly interface for Windows operation system.

Open Source Template Engines in C#

  • NVelocity - NVelocity is a .Net-based template engine. It permits anyone to use the simple yet powerful template language to reference objects defined in .Net code.

Open Source Testing Tools in C#

  • NUnit - NUnit is a unit-testing framework for all .Net languages. Initially ported from JUnit

Open Source Web Frameworks in C#

  • Maverick.NET - Maverick.NET is a .NET port of Maverick, a Model-View-Controller (aka "Model 2") framework for web publishing. It is a minimalist framework which focuses solely on MVC logic, allowing you to generate presentation using a variety of templating and transformation technologies.

Open Source Web Mail Clients in C#

  • SharpWebMail - SharpWebMail is an ASP.NET Web Mail application that is written in C#. It uses a POP3 server as the mailstore and sends mail through a SMTP. It is very simple to configure (Only a few settings in the web.config file). You can compose HTML messages, search your inbox, read complex mime messages and much more.

Open Source Web Testing Tools in C#

  • NUnitAsp - NUnitAsp is a tool for automatically testing ASP.NET web pages. It's an extension to NUnit

Open Source Wiki Engines in C#

  • SushiWiki - SushiWiki is a WikiWikiWeb like Web application written in C#

Open Source XML Parsers in C#

  • SAX.NET - SAX dot NET is a C# port of the original Java based SAX API specifications.
posted @ 2006-07-28 10:25 幸运儿 阅读(202) 评论(0) 编辑
摘要: using System;using System.Text;using System.Text.RegularExpressions;namespace myluntan{/// <summary>/// UBB 的摘要说明。/// </summary>public class UBB{ public UBB() { // // TODO: 在此处添加构造函数逻辑 // ...阅读全文
posted @ 2006-05-18 10:35 幸运儿 阅读(216) 评论(0) 编辑