Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Date Format in String Builder
Message
De
03/06/2014 15:17:11
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01601157
Message ID:
01601230
Vues:
29
This message has been marked as a message which has helped to the initial question of the thread.
>>>
>>>sbResult.AppendFormat("{0,20}", row.Field<DateTime?>("date_time").ToString("G"));
>>>
>>>But how to get rid of last AM/PM (BTW, not sure why VFP is removing it as the time will be ambiguous). Same thing of getting rid of last 3 chars?
>>
>>Think if you change the format G and specify 24 hour format, it should not be a problem
>>
>>Console.WriteLine("{0,20:MM/dd/yyyy HH:mm:ss}", DateTime.Now);
>>
>>http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
>
>I don't understand where is my problem now. Why do I have extra spaces in the beginning I don't have in VFP:
>
>
><ERR>0</ERR><STATUSCODE>0</STATUSCODE><MSG># of Scans: 3
>4/7/2009 5:42:03     1/         TICKET     ADMIN      Valid
>4/7/2009 5:41:35     1/         TICKET     ADMIN      Invalid
>4/7/2009 5:41:29     1/         TICKET     ADMIN      Invalid
></MSG>
><ERR>0</ERR><STATUSCODE>0</STATUSCODE><MSG># of Scans: 3
>   4/7/2009 17:42:03         1/ TICKET     ADMIN      Valid
>   4/7/2009 17:41:35         1/ TICKET     ADMIN      Invalid
>   4/7/2009 17:41:29         1/ TICKET     ADMIN      Invalid
></MSG>
>
>Top is VFP and bottom is C#.
>
>VFP code:
>
> lvRetVal=lvRetVal+'# of Scans: '+transform(reccount())+chr(13)+chr(10)
>                  scan
>                     lvRetVal=lvRetVal+;
>                        padr(substr(transform(date_time),1,len(transform(date_time))-3),20)+' '+;
>                        padr(location2,10)+' '+padr(location,10)+' '+padr(person,10)+' '+;
>                        iif(activ_type=110,'Valid', iif(activ_type=111,'Invalid', 'Valid (rescan)'))+chr(13)+chr(10)
>
>and this is my C# code:
>
>
>sbResult.AppendFormat("{0,20:M/d/yyyy H:mm:ss} {1,10} {2,10} {3,10} {4}\r\n", 
>                        row.Field<DateTime?>("date_time"), row.Field<String>("location2"),
>                        row.Field<String>("location"), row.Field<String>("person"), validStatus);
>
>Do you see why I have spaces in the beginning of the string and why 1/ is not at the same place?
>
>Thanks again.

http://msdn.microsoft.com/en-us/library/system.string.format.aspx#FormatItem
Note what the sign on the alignment parameter indicates.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform