Se convierten en DateTime y se aplica el Compare
Tipo de valor
Condición
Menor que cero
t1 es menor que t2.
Cero
t1 es igual a t2.
Mayor que cero
t1 es mayor que t2.
public static int Compare (
DateTime t1,
DateTime t2
)
CRMDateTime To DateTime
When working with CrmDateTime, you'll notice that this type does have a .value attribute,
but the type of this attribute is string. There is no attribute to get the .net class DateTime out of your CrmDateTime.
If you do want to use a DateTime anyway, you'd easily need to convert it. You could use any of these:
Convert.ToDateTime(crmdatetime.Value)
DateTime.Parse(crmdatetime.Value)
For more information on the CrmDateTime, look in the SDK:
http://msdn2.microsoft.com/en-us/library/aa613542.aspx
DateTime to CRMDateTime
static public CrmDateTime ConvertToCRMDateTime(DateTime dateTime) {
CrmDateTime crmDateTime = new CrmDateTime();
crmDateTime.date = dateTime.ToShortDateString();
crmDateTime.time = dateTime.ToShortTimeString();
TimeSpan offset = TimeZone.CurrentTimeZone.GetUtcOffset(dateTime);
string sOffset = string.Empty;
if (offset.Hours < 0) {
sOffset = "-" + offset.ToString().Substring(1, 4);
}
else {
sOffset = "+" + offset.ToString().Substring(0, 5);
}
//sOffset += offset.Minutes.ToString().PadLeft(2, '0');
crmDateTime.Value = dateTime.ToString(string.Format("yyyy-MM-ddTHH:mm:ss{0}", sOffset));
return crmDateTime;
}
Uso de formato de fechas según cultura e idioma
DateTimeFormatInfo dfi = new DateTimeFormatInfo();
//CultureInfo ci = new CultureInfo("es-ES");
CultureInfo ci = new CultureInfo("en-US");
dfi.MonthDayPattern = "MM-MMMM, ddd-dddd";
DateTime time = new DateTime();
time = DateTime.Now;
Label1.Text = time.ToString("f",ci);
No hay comentarios:
Publicar un comentario