IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

[C#] DateTime - Server english / French


Sujet :

ASP.NET

  1. #1
    Membre régulier
    Inscrit en
    Avril 2004
    Messages
    83
    Détails du profil
    Informations forums :
    Inscription : Avril 2004
    Messages : 83
    Points : 77
    Points
    77
    Par défaut [C#] DateTime - Server english / French
    Bonjour à tous,

    J'ai un petit soucis avec un DateTime.

    J'ai developpé mon application sous windows XP version Française.
    Ce matin, je l'ai mis en production sur un serveur Windows version english.

    La page d'accueil de mon appli renseigne la date du jour.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <%= DateTime.Now.ToLongDateString()%>
    Bilan sur mon serveur de dev j'ai :
    Nous sommes le vendredi 4 juin 2004 ,
    Sur le prod :
    Nous sommes le Friday, June 04, 2004 ,
    J'ai checké les parametres régionaux mais tout est ok de ce coté la.
    DateTime semble utiliser pourtant des parametres windows ...

    Avez vous une idée ?

    Merci de votre aide.

    Damien

  2. #2
    Membre régulier
    Inscrit en
    Avril 2004
    Messages
    85
    Détails du profil
    Informations forums :
    Inscription : Avril 2004
    Messages : 85
    Points : 77
    Points
    77
    Par défaut
    Repris de msdn library

    Parse
    The following code example illustrates the use of the Parse method to convert a string into a DateTime. This example uses the culture associated with the current thread to perform the parse. If the CultureInfo associated with the current culture cannot parse the input string, a FormatException is thrown.
    [Visual Basic]
    Dim MyString As String = "Jan 1, 2002"
    Dim MyDateTime As DateTime = DateTime.Parse(MyString)
    Console.WriteLine(MyDateTime)
    [C#]
    string MyString = "Jan 1, 2002";
    DateTime MyDateTime = DateTime.Parse(MyString);
    Console.WriteLine(MyDateTime);
    You can also specify a CultureInfo set to one of the cultures defined by that object. The following code example uses a format provider to parse a German string into a DateTime. A CultureInfo representing the de-DE culture is defined and passed with the string being parsed to ensure successful parsing of this particular string. This precludes whatever setting is in the CurrentCulture of the CurrentThread.
    [Visual Basic]
    Imports System.Globalization

    Dim MyCultureInfo As CultureInfo = new CultureInfo("de-DE")
    Dim MyString As String = "12 Juni 2002"
    Dim MyDateTime As DateTime = DateTime.Parse(MyString, MyCultureInfo)
    Console.WriteLine(MyDateTime)
    [C#]
    using System.Globalization;

    CultureInfo MyCultureInfo = new CultureInfo("de-DE");
    string MyString = "12 Juni 2002";
    DateTime MyDateTime = DateTime.Parse(MyString, MyCultureInfo);
    Console.WriteLine(MyDateTime);
    The following code example uses the DateTimeStyles enumeration to specify that the current date and time information should not be added to the DateTime for fields that the string does not define.
    [Visual Basic]
    Imports System.Globalization

    Dim MyCultureInfo As CultureInfo = new CultureInfo("de-DE")
    Dim MyString As String = "12 Juni 2002"
    Dim MyDateTime As DateTime = DateTime.Parse(MyString, MyCultureInfo, DateTimeStyles.NoCurrentDateDefault)
    Console.WriteLine(MyDateTime)
    [C#]
    using System.Globalization;

    CultureInfo MyCultureInfo = new CultureInfo("de-DE");
    string MyString = "12 Juni 2002";
    DateTime MyDateTime = DateTime.Parse(MyString, MyCultureInfo, DateTimeStyles.NoCurrentDateDefault);
    Console.WriteLine(MyDateTime);
    ParseExact
    The ParseExact method only converts the specified string pattern to a DateTime. When a string that is not of the form specified is passed to this method, a FormatException is thrown. You can specify one of the standard date and time format specifiers or a limited combination of the custom date and time format specifiers. Using the custom format specifiers, it is possible for you to construct a custom recognition string. For an explanation of the specifiers, see the section on date and time format strings.
    In the following code example, the ParseExact method is passed a string object to parse, followed by a format specifier, followed by a CultureInfo object. This ParseExact method can only parse strings that exhibit the long date pattern in the en-US culture.
    [Visual Basic]
    Imports System.Globalization

    Dim MyCultureInfo As CultureInfo = new CultureInfo("en-US")
    Dim MyString As String = "Tuesday, April 10, 2001"
    Dim MyDateTime As DateTime = DateTime.ParseExact(MyString, "D", MyCultureInfo)
    Console.WriteLine(MyDateTime)
    [C#]
    using System.Globalization;

    CultureInfo MyCultureInfo = new CultureInfo("en-US");
    string MyString = " Tuesday, April 10, 2001";
    DateTime MyDateTime = DateTime.ParseExact(MyString, "D", MyCultureInfo);
    Console.WriteLine(MyDateTime);

  3. #3
    Membre régulier
    Inscrit en
    Avril 2004
    Messages
    83
    Détails du profil
    Informations forums :
    Inscription : Avril 2004
    Messages : 83
    Points : 77
    Points
    77
    Par défaut
    Merci mais je ne suis pas expert dans les cultureInfo ...
    Est ce que tu peux traduire ce charabia s'il te plait ?

    Merci de ton aide.

    Damien

  4. #4
    Expert éminent

    Avatar de freegreg
    Profil pro
    Inscrit en
    Août 2002
    Messages
    4 376
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Août 2002
    Messages : 4 376
    Points : 8 779
    Points
    8 779

  5. #5
    Membre régulier
    Inscrit en
    Avril 2004
    Messages
    85
    Détails du profil
    Informations forums :
    Inscription : Avril 2004
    Messages : 85
    Points : 77
    Points
    77
    Par défaut
    puissant merci freegreg :0)

  6. #6
    Membre régulier
    Inscrit en
    Avril 2004
    Messages
    83
    Détails du profil
    Informations forums :
    Inscription : Avril 2004
    Messages : 83
    Points : 77
    Points
    77
    Par défaut
    Pour ceux que cela interesse, j'ai résolu mon problème.
    Il fallait spécifier une culture par défaut car dans le cas contraire, il prenait le langage du framework.

    Il suffit donc de faire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <globalization 
                culture="fr-FR"
                requestEncoding="utf-8" 
                responseEncoding="utf-8" 
       />
    Voila, merci à ceux qui se sont penchés sur mon problème.

    A plus,

    Damien

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 6
    Dernier message: 21/09/2007, 13h35
  2. [SQL SERVER] DateTime et smalldatetime
    Par aityahia dans le forum Bases de données
    Réponses: 1
    Dernier message: 30/07/2006, 10h24
  3. [SQL Server] Récupérer datetime
    Par le_highlander dans le forum Langage SQL
    Réponses: 1
    Dernier message: 20/04/2006, 15h31
  4. Réponses: 3
    Dernier message: 10/08/2005, 11h11
  5. Convertir une date au format excel en datetime SQL server
    Par ALLB dans le forum MS SQL Server
    Réponses: 8
    Dernier message: 20/07/2004, 11h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo