DateTimePicker custom format : DateTimePicker « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » DateTimePicker 
23.14.4.DateTimePicker custom format
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Form1 : System.Windows.Forms.Form {
    private System.Windows.Forms.DateTimePicker dateTimePicker1;
    private System.Windows.Forms.DateTimePicker dateTimePicker2;
    private System.Windows.Forms.DateTimePicker dateTimePicker3;
    private System.Windows.Forms.DateTimePicker dateTimePicker4;
    private System.Windows.Forms.DateTimePicker dateTimePicker5;
    private System.Windows.Forms.DateTimePicker dateTimePicker6;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.Label label5;
    private System.Windows.Forms.Label label7;
    public Form1() {
        this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
        this.dateTimePicker2 = new System.Windows.Forms.DateTimePicker();
        this.dateTimePicker3 = new System.Windows.Forms.DateTimePicker();
        this.dateTimePicker4 = new System.Windows.Forms.DateTimePicker();
        this.dateTimePicker5 = new System.Windows.Forms.DateTimePicker();
        this.dateTimePicker6 = new System.Windows.Forms.DateTimePicker();
        this.label1 = new System.Windows.Forms.Label();
        this.label2 = new System.Windows.Forms.Label();
        this.label3 = new System.Windows.Forms.Label();
        this.label4 = new System.Windows.Forms.Label();
        this.label5 = new System.Windows.Forms.Label();
        this.label7 = new System.Windows.Forms.Label();
        this.SuspendLayout();
        // 
        // dateTimePicker1
        // 
        this.dateTimePicker1.CustomFormat = "hh:mm:s : MM/dd/yy";
        this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
        this.dateTimePicker1.Location = new System.Drawing.Point(1616);
        this.dateTimePicker1.Name = "dateTimePicker1";
        this.dateTimePicker1.Size = new System.Drawing.Size(24020);
        this.dateTimePicker1.TabIndex = 0;
        // 
        // dateTimePicker2
        // 
        this.dateTimePicker2.CustomFormat = "h/mm/ss : dd.MM.yyyy";
        this.dateTimePicker2.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
        this.dateTimePicker2.Location = new System.Drawing.Point(1656);
        this.dateTimePicker2.Name = "dateTimePicker2";
        this.dateTimePicker2.Size = new System.Drawing.Size(24020);
        this.dateTimePicker2.TabIndex = 0;
        // 
        // dateTimePicker3
        // 
        this.dateTimePicker3.CustomFormat = "HH-mm-ss : MMMM/dd/yyyy  tt";
        this.dateTimePicker3.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
        this.dateTimePicker3.Location = new System.Drawing.Point(1688);
        this.dateTimePicker3.Name = "dateTimePicker3";
        this.dateTimePicker3.Size = new System.Drawing.Size(24020);
        this.dateTimePicker3.TabIndex = 0;
        // 
        // dateTimePicker4
        // 
        this.dateTimePicker4.CustomFormat = "tt hh/mm/ss : dddd.MMMM.yyyy";
        this.dateTimePicker4.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
        this.dateTimePicker4.Location = new System.Drawing.Point(16200);
        this.dateTimePicker4.Name = "dateTimePicker4";
        this.dateTimePicker4.Size = new System.Drawing.Size(24020);
        this.dateTimePicker4.TabIndex = 0;
        // 
        // dateTimePicker5
        // 
        this.dateTimePicker5.CustomFormat = "HH/mm/ss : ddd-MM-yy";
        this.dateTimePicker5.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
        this.dateTimePicker5.Location = new System.Drawing.Point(16160);
        this.dateTimePicker5.Name = "dateTimePicker5";
        this.dateTimePicker5.Size = new System.Drawing.Size(24020);
        this.dateTimePicker5.TabIndex = 0;
        // 
        // dateTimePicker6
        // 
        this.dateTimePicker6.CustomFormat = "hh/mm/ss : dddd MMMM yyyy tt";
        this.dateTimePicker6.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
        this.dateTimePicker6.Location = new System.Drawing.Point(16128);
        this.dateTimePicker6.Name = "dateTimePicker6";
        this.dateTimePicker6.Size = new System.Drawing.Size(24020);
        this.dateTimePicker6.TabIndex = 0;
        this.dateTimePicker6.Value = new System.DateTime(2002514142800);
        // 
        // label1
        // 
        this.label1.Font = new System.Drawing.Font("Courier New"11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
        this.label1.Location = new System.Drawing.Point(26416);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(35223);
        this.label1.TabIndex = 1;
        this.label1.Text = "Format : hh:mm:ss : MM/dd/yy";
        // 
        // label2
        // 
        this.label2.Font = new System.Drawing.Font("Courier New"11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
        this.label2.Location = new System.Drawing.Point(26456);
        this.label2.Name = "label2";
        this.label2.Size = new System.Drawing.Size(35223);
        this.label2.TabIndex = 2;
        this.label2.Text = "Format : h/mm/ss : dd.MM.yyyy";
        // 
        // label3
        // 
        this.label3.Font = new System.Drawing.Font("Courier New"11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
        this.label3.Location = new System.Drawing.Point(26488);
        this.label3.Name = "label3";
        this.label3.Size = new System.Drawing.Size(35223);
        this.label3.TabIndex = 3;
        this.label3.Text = "Format : HH-mm-ss : MMMM/dd/yyyy  tt";
        // 
        // label4
        // 
        this.label4.Font = new System.Drawing.Font("Courier New"11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
        this.label4.Location = new System.Drawing.Point(264160);
        this.label4.Name = "label4";
        this.label4.RightToLeft = System.Windows.Forms.RightToLeft.No;
        this.label4.Size = new System.Drawing.Size(35223);
        this.label4.TabIndex = 5;
        this.label4.Text = "Format : HH/mm/ss : ddd-MM-yy";
        // 
        // label5
        // 
        this.label5.Font = new System.Drawing.Font("Courier New"11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
        this.label5.Location = new System.Drawing.Point(264128);
        this.label5.Name = "label5";
        this.label5.Size = new System.Drawing.Size(35223);
        this.label5.TabIndex = 4;
        this.label5.Text = "Format : hh/mm/ss : dddd MMMM yyyy tt";
        // 
        // label7
        // 
        this.label7.Font = new System.Drawing.Font("Courier New"11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
        this.label7.Location = new System.Drawing.Point(264200);
        this.label7.Name = "label7";
        this.label7.Size = new System.Drawing.Size(35223);
        this.label7.TabIndex = 6;
        this.label7.Text = "Format : tt hh/mm/ss : dddd.MMMM.yyyy";
        // 
        // Form1
        // 
        this.AutoScaleBaseSize = new System.Drawing.Size(513);
        this.ClientSize = new System.Drawing.Size(632245);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.label7,
                                      this.label4,
                                      this.label5,
                                      this.label3,
                                      this.label2,
                                      this.label1,
                                      this.dateTimePicker1,
                                      this.dateTimePicker2,
                                      this.dateTimePicker3,
                                      this.dateTimePicker4,
                                      this.dateTimePicker5,
                                      this.dateTimePicker6});
        this.Name = "Form1";
        this.Text = "DateTime Formats";
        this.Load += new System.EventHandler(this.Form1_Load);
        this.ResumeLayout(false);

    }

    [STAThread]
    static void Main() {
        Application.Run(new Form1());
    }

    private void Form1_Load(object sender, System.EventArgs e) {
    }
}
23.14.DateTimePicker
23.14.1.DateTimePicker Event and selected valueDateTimePicker Event and selected value
23.14.2.DateTimePicker: look and feel and data formatDateTimePicker: look and feel and data format
23.14.3.DataTime BoldedDatesDataTime BoldedDates
23.14.4.DateTimePicker custom format
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.