Nitin Dhiman. Powered by Blogger.

.NET Custom DateTime Format Strings

No comments
.NET Custom DateTime Format Strings
SpecifierDescription
dRepresents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero.
ddRepresents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero.
dddRepresents the abbreviated name of the day of the week as defined in the current System.Globalization.DateTimeFormatInfo.AbbreviatedDayNames property.
ddddRepresents the full name of the day of the week as defined in the current System.Globalization.DateTimeFormatInfo.DayNames property.
fRepresents the most significant digit of the seconds fraction. Note that if the "f" format specifier is used alone, without other format specifiers, it is interpreted as the "f" standard DateTime format specifier (full date/time pattern). When you use this format specifier with the ParseExact or TryParseExact method, the number of "f" format specifiers that you use indicates the number of most significant digits of the seconds fraction to parse.
ff…Number of repeated specifiers represents most significant digits of the seconds fraction.
FRepresents the most significant digit of the seconds fraction. Nothing is displayed if the digit is zero. When you use this format specifier with the ParseExact or TryParseExact method, the number of "F" format specifiers that you use indicates the maximum number of most significant digits of the seconds fraction to parse.
FF…Number of repeated specifiers represents most significant digits of the seconds fraction. Trailing zeros, or two zero digits, are not displayed.
g or ggRepresents the period or era (A.D. for example). This specifier is ignored if the date to be formatted does not have an associated period or era string.
hRepresents the hour as a number from 1 through 12, that is, the hour as represented by a 12-hour clock that counts the whole hours since midnight or noon. A single-digit hour is formatted without a leading zero.
hhRepresents the hour as a number from 01 through 12, that is, the hour as represented by a 12-hour clock that counts the whole hours since midnight or noon. A single-digit hour is formatted with a leading zero.
HRepresents the hour as a number from 0 through 23, that is, the hour as represented by a zero-based 24-hour clock that counts the hours since midnight. A single-digit hour is formatted without a leading zero.
HHRepresents the hour as a number from 00 through 23, that is, the hour as represented by a zero-based 24-hour clock that counts the hours since midnight. A single-digit hour is formatted with a leading zero.
KRepresents different values of the DateTime.Kind property, that is, Local, Utc, or Unspecified. This specifier round-trips the kind value in text and preserves the time zone. For the Local kind value, this specifier is equivalent to the "zzz" specifier and displays the local offset, for example, "-07:00". For the Utc kind value, the specifier displays a "Z" character to represent a UTC date. For the Unspecified kind value, the specifier is equivalent to "" (nothing).
mRepresents the minute as a number from 0 through 59. The minute represents whole minutes passed since the last hour. A single-digit minute is formatted without a leading zero.
mmRepresents the minute as a number from 00 through 59. The minute represents whole minutes passed since the last hour. A single-digit minute is formatted with a leading zero.
MRepresents the month as a number from 1 through 12. A single-digit month is formatted without a leading zero.
MMRepresents the month as a number from 01 through 12. A single-digit month is formatted with a leading zero.
MMMRepresents the abbreviated name of the month as defined in the current System.Globalization.DateTimeFormatInfo.AbbreviatedMonthNames property.
MMMMRepresents the full name of the month as defined in the current System.Globalization.DateTimeFormatInfo.MonthNames property.
sRepresents the seconds as a number from 0 through 59. The second represents whole seconds passed since the last minute. A single-digit second is formatted without a leading zero.
ssRepresents the seconds as a number from 00 through 59. The second represents whole seconds passed since the last minute. A single-digit second is formatted with a leading zero.
tRepresents the first character of the A.M./P.M. designator defined in the current System.Globalization.DateTimeFormatInfo.AMDesignator or System.Globalization.DateTimeFormatInfo.PMDesignator property.
ttRepresents the A.M./P.M. designator as defined in the current System.Globalization.DateTimeFormatInfo.AMDesignator or System.Globalization.DateTimeFormatInfo.PMDesignator property.
yRepresents the year as at most a two-digit number. If the year has more than two digits, only the two low-order digits appear in the result. If the year has fewer than two digits, the number is formatted without a leading zero.
yyRepresents the year as a two-digit number. If the year has more than two digits, only the two low-order digits appear in the result. If the year has fewer than two digits, the number is padded with leading zeroes to achieve two digits.
yyyRepresents the year as a three-digit number. If the year has more than three digits, only the three low-order digits appear in the result. If the year has fewer than three digits, the number is padded with leading zeroes to achieve three digits. Note that for the Thai Buddhist calendar, which can have five-digit years, this format specifier displays all five digits.
yyyyRepresents the year as a four-digit number. If the year has more than four digits, only the four low-order digits appear in the result. If the year has fewer than four digits, the number is padded with leading zeroes to achieve four digits. Note that for the Thai Buddhist calendar, which can have five-digit years, this format specifier renders all five digits.
yyyyyRepresents the year as a five-digit number. If the year has more than five digits, only the five low-order digits appear in the result. If the year has fewer than five digits, the number is padded with leading zeroes to achieve five digits. If there are additional "y" specifiers, the number is padded with as many leading zeroes as necessary to achieve the number of "y" specifiers.
zRepresents the signed time zone offset of your system from Greenwich Mean Time (GMT) measured in hours. For example, the offset for a computer in the Pacific Standard Time zone is "-8". The offset is always displayed with a leading sign. A plus sign (+) indicates hours ahead of GMT and a minus sign (-) indicates hours behind GMT. The offset ranges from –12 through +13. A single-digit offset is formatted without a leading zero. The offset is affected by daylight savings time.
zzRepresents the signed time zone offset of your system from Greenwich Mean Time (GMT) measured in hours. For example, the offset for a computer in the Pacific Standard Time zone is "-08". The offset is always displayed with a leading sign. A plus sign (+) indicates hours ahead of GMT and a minus sign (-) indicates hours behind GMT. The offset ranges from –12 through +13. A single-digit offset is formatted with a leading zero. The offset is affected by daylight savings time.
zzzRepresents the signed time zone offset of your system from Greenwich Mean Time (GMT) measured in hours and minutes. For example, the offset for a computer in the Pacific Standard Time zone is "-08:00". The offset is always displayed with a leading sign. A plus sign (+) indicates hours ahead of GMT and a minus sign (-) indicates hours behind GMT. The offset ranges from –12 through +13. A single-digit offset is formatted with a leading zero. The offset is affected by daylight savings time.
:The time separator defined in the current System.Globalization.DateTimeFormatInfo.TimeSeparator property that is used to differentiate hours, minutes, and seconds.
/The date separator defined in the current System.Globalization.DateTimeFormatInfo.DateSeparator property that is used to differentiate years, months, and days.
"Quoted string (quotation mark). Displays the literal value of any string between two quotation marks ("). Precede each quotation mark with an escape character (\).
'Quoted string (apostrophe). Displays the literal value of any string between two apostrophe (') characters.
%cRepresents the result associated with a custom format specifier "c", when the custom DateTime format string consists solely of that custom format specifier. That is, to use the "d", "f", "F", "h", "m", "s", "t", "y", "z", "H", or "M" custom format specifier by itself, specify "%d", "%f", "%F", "%h", "%m", "%s", "%t", "%y", "%z", "%H", or "%M".
\cThe escape character. Displays the character "c" as a literal when that character is preceded by the escape character (\). To insert the backslash character itself in the result string, use two escape characters ("\\").
Any other char.Any other character is copied to the result string, and does not affect formatting.

No comments :

Post a Comment

.NET Standard DateTime Format Strings

No comments

.NET Standard DateTime Format Strings

Specifier

Name

Description

d

Short date pattern

Represents a custom DateTime format string defined by the current ShortDatePattern
property.

D

Long date pattern

Represents a custom DateTime format string defined by the current LongDatePattern
property.

f

Full date/time pattern (short time)

Represents a combination of the long date (D) and short time (t) patterns, separated
by a space.

F

Full date/time pattern (long time)

Represents a custom DateTime format string defined by the current FullDateTimePattern
property.

g

General date/time pattern (short time)

Represents a combination of the short date (d) and short time (t) patterns, separated
by a space.

G

General date/time pattern (long time)

Represents a combination of the short date (d) and long time (T) patterns, separated
by a space.

M or m

Month day pattern

Represents a custom DateTime format string defined by the current MonthDayPattern
property.

o

Round-trip date/time pattern

Represents a custom DateTime format string using a pattern that preserves time zone
information. The pattern is designed to round-trip DateTime formats, including the
Kind property, in text. Then the formatted string can be parsed back using Parse
or ParseExact with the correct Kind property value. Equivalent custom format string
is "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK".

R or r

RFC1123 pattern

Represents a custom DateTime format string defined by the current RFC1123Pattern
property. The pattern is a defined standard and the property is readonly. Equivalent
custom format string is "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'". Does not convert
DateTimes to UTC.

s

Sortable date/time pattern; ISO 8601

Represents a custom DateTime format string defined by the current SortableDateTimePattern
property. This pattern is a defined standard and the property is read-only. Equivalent
custom format string is "yyyy'-'MM'-'dd'T'HH':'mm':'ss".

t

Short time pattern

Represents a custom DateTime format string defined by the current ShortTimePattern
property. For example, the custom format string for the invariant culture is "HH:mm".

T

Long time pattern

Represents a custom DateTime format string defined by the current LongTimePattern
property. For example, the custom format string for the invariant culture is "HH:mm:ss".

u

Universal sortable date/time pattern

Represents a custom DateTime format string defined by the current UniversalSortableDateTimePattern
property. Equivalent custom format string is "yyyy'-'MM'-'dd HH':'mm':'ss'Z'". Does
not convert DateTimes to UTC.

U

Universal sortable date/time pattern

Represents a custom DateTime format string defined by the current FullDateTimePattern
property. This pattern is the same as the full date/long time (F) pattern. However,
formatting operates on the Coordinated Universal Time (UTC) that is equivalent to
the DateTime object being formatted.

Y or y

Year month pattern

Represents a custom DateTime format string defined by the current YearMonthPattern
property. For example, the custom format string for the invariant culture is "yyyy
MMMM".

Any other single character

(Unknown specifier)

An unknown specifier throws a runtime format exception.

No comments :

Post a Comment

Casecading dropdown using JQuery.

No comments
1) Put the following JavaScript function on the page:

function BindDropDown(dropdown_parent,dropdown_child,selectedVal)
{
if(document.getElementById(dropdown_parent).selectedIndex>0)
{
$.ajax
({
url: "/GetAjaxData.aspx",
data: "type=products&value="+document.getElementById(dropdown_parent).options[document.getElementById(dropdown_parent).selectedIndex].value,
success: function(message1)
{
var selectedindex=0;
var rows1 = message1.split("\n");
var iCount = 0;
document.getElementById(dropdown_child).options.length = 0;
for (iCount = 0; iCount < rows1.length; iCount++)
{
var valu=rows1[iCount].split("|");
if(valu[1].replace(/^\s*/, "").replace(/\s*$/, "")==selectedVal)
selectedindex=iCount;
var oOption = new Option(valu[0],valu[1].replace(/^\s*/, "").replace(/\s*$/, ""));
document.getElementById(dropdown_child).options.add(oOption);
}
document.getElementById(dropdown_child).options[selectedindex].selected=true;
return false;
}
});
}
else
{
document.getElementById(dropdown_child).options.length = 0;
document.getElementById(dropdown_child).options.add(new Option("--Select--", "0"));
}
}

2) Call The Following function on dropdown's selected index change:


 BindProducts('<%=ddlParent.ClientID%>', '<%=ddlChild.ClientID%>', '<%=Id%>')


3) Put the following code on the GetAjaxData.aspx page:

protected void Page_Load(object sender, EventArgs e)
{
ReturnDDLData(Convert.ToInt32(Request.QueryString["value"]));
}
private void ReturnDDLData(Int32 selectedId)
{
Response.Clear();
StringBuilder sbResponse = new StringBuilder();
Collection m_oCollection = new Collection();
m_oCollection.GetCollection(selectedId);
sbResponse.Append(string.Concat("--Select--", "|0", Environment.NewLine));
foreach (Product m_oItem in m_oCollection)
{
sbResponse.Append(string.Concat(m_oItem.Name, "|", m_oItem.ID.Value.ToString().Trim()) + Environment.NewLine);
}
Response.Output.Write(sbResponse.ToString().Substring(0, sbResponse.ToString().LastIndexOf(Environment.NewLine)));
Response.End();
}

No comments :

Post a Comment

Create a Windows Service in .net

No comments
Hi,
Following are the steps to create a basic windows service to write a file in .net:
include following namespaces:
using System.Text;
using System.IO;
using System.Timers;
Create a class level timer:
    private Timer timer = new Timer();
On Start Event:
    protected override void OnStart(string[] args)
    {
        timer.Elapsed += new ElapsedEventHandler(TimerElapsed);
        timer.Interval = 10000;
        timer.Enabled = true;
    }
Create Event handler:
    private void TimerElapsed(object source, ElapsedEventArgs e)
    {
        Logger();
    }
Create function:
    public void Logger()
    {
        string mydocument =
      Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        string[] txtList = Directory.GetFiles(mydocument, "*.txt");
        StringBuilder sb = new StringBuilder();
        string FileName = @"\log.txt";
        using (StreamReader sr = new StreamReader(mydocument + FileName))
        {
            sb.AppendLine(DateTime.Now.ToString());
            sb.AppendLine("---------------------------------------------");
            sb.Append(sr.ReadToEnd());
            sb.AppendLine();
        }
        using (StreamWriter outfile =
            new StreamWriter(mydocument + FileName))
        {
            outfile.Write(sb.ToString());
        }
    }


InstallUtil command to install the service:
    installutil ServicePath/Servicename.exe


To uninstall the service:
    installutil /u ServicePath/Servicename.exe

No comments :

Post a Comment