USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  C# - converter string para datetime
Martini
Pontos: 2843 Pontos: 2843
PAROBÉ
RS - BRASIL
Postada em 07/02/2006 08:02 hs         
olá pessoal,
 
alguém sabe com eu converto uma string para datetime em C#? a minha string está neste formato "20060207" -->yyyymmdd
 
Obrigado
     
Martini
Pontos: 2843 Pontos: 2843
PAROBÉ
RS - BRASIL
Postada em 07/02/2006 10:02 hs         
pessoal,
 
já está resolvido ... o meu colega fez ...
 
public static DateTime ConverteFTypeDateTime(object o)
  {
   DateTime retorno;
   if (o.GetType() == typeof(System.String))
   {
    try
    {
     retorno = Convert.ToDateTime(o);
    }
    catch(System.FormatException)
    {
     string aux = (string)o;
     if (aux.IndexOf("-") == -1 && aux.IndexOf("/") == -1 && aux.Length == 8)
     {
      try
      {
       retorno = Convert.ToDateTime(String.Format("{0}/{1}/{2}",aux.Substring(6,2),aux.Substring(4,2),aux.Substring(0,4)));
      }
      catch(Exception)
      {
       throw new Exception("Erro ao converter o tipo de dado!");
      }
     }
     else
     {
      throw new Exception("Erro ao converter o tipo de dado!");
     }
    }
    catch(Exception ex)
    {
     throw ex;
    }
   }
   else
   {
    retorno = (DateTime) Convert.ChangeType(o,typeof(DateTime));
   }
   return retorno;
  }
 
 
valeu!!!
     
MARCONE
Pontos: 2843
BRASÍLIA
DF - BRASIL
Postada em 07/02/2006 14:48 hs            
Parece ser mais fácil que o VB.NET (rs..)..

MarconeEmoções

 

     
Página(s): 1/1    


Seu Nome:

Seu eMail:

ALTERAR PARA MODO HTML
Mensagem:

[:)] = 
[:P] = 
[:(] = 
[;)] = 

HTML DESLIGADO

     
 VOLTAR

  



CyberWEB Network Ltda.    © Copyright 2000-2026   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página