C# There's a better way to do it yourself ,Net arbitrarily String Format conversion to DateTime type

====================================================== original text ======================================================

I haven't updated my log for a long time , Add a method , There's no technology in itself , For the convenience of all of you , I'll sort it out a little bit ~

Characters with milliseconds are converted to time (DateTime) Format general method , as follows : Support formats :2014-10-10 10:10:10,666 or 2014-10-10 10:10:10 666)

/// <summary>
/// Characters with milliseconds are converted to time (DateTime) Format
/// Processable format :[2014-10-10 10:10:10,666 or 2014-10-10 10:10:10 666]
/// </summary>
public DateTime GetDateTime(string dateTime)
{
string[] strArr = dateTime.Split(new char[] { '-', ' ', ':', ',' });
DateTime dt = new DateTime(int.Parse(strArr[]),
int.Parse(strArr[]),
int.Parse(strArr[]),
int.Parse(strArr[]),
int.Parse(strArr[]),
int.Parse(strArr[]),
int.Parse(strArr[]));
return dt;
}

Call the following :

DateTime dateTime1 = GetDateTime("2014-11-21 15:39:53,504");

Characters with milliseconds are converted to time (DateTime) More related articles on general methods of format

  1. mysql Convert characters to numbers

    In operation mysql when , It's often necessary to convert characters into numbers , This step is simple , But it's easy to forget the words that are not often used , Now the methods found on the Internet are recorded as follows : 1. Convert the number of a character to a number , such as '0' Turn into 0 It can be realized directly by addition, for example : take pony surface ...

  2. Java-Runoob- Advanced tutorials - example - Time processing :04. Java example - Time stamp converted to time

    ylbtech-Java-Runoob- Advanced tutorials - example - Time processing :04. Java example - Time stamp converted to time 1. Return to the top 1. Java example - Time stamp converted to time  Java example The following example demonstrates ...

  3. vue element-ui The time stamp in the table is converted to time display

    Work encountered in the background to the table data, the time is a 13 Bit time stamp , It needs to be converted into time and displayed in the table , It can be used element-ui The form comes with it :formatter function , To format the table contents : // Time stamp converted to time // Use ...

  4. Linux c Non printable characters in a string are converted to 16 Base number

    This paper is written by www.169it.com Collection and arrangement If one C The string contains both printable and unprintable characters , If you want to write this string to a file , At the same time, it is convenient to open the file to view or print it out in the console, without garbled code , So you can put the ...

  5. js Convert date format to time format

    A way to write by yourself function split_time(time){// Convert current time to time   for example 2013-09-11 12:12:12   var arr=time.split(" ...

  6. js Time stamp is converted to time format in

    js Time stamp is converted to time format in , // Time stamp to time format var formatDate = function(date){ date = new Date(date); var y=date.getF ...

  7. c#: Cannot be NULL convert to “System.DateTime”, Because it's a value type

    Excerpt from :http://www.blogjava.net/parable-myth/archive/2010/09/30/333454.html stay C# 2.0 In the data type , It is divided into value type and reference type , quote ...

  8. c#: Cannot be NULL convert to “System.DateTime”, Because it's a value type ( turn )

    Excerpt from :http://www.blogjava.net/parable-myth/archive/2010/09/30/333454.html stay C# 2.0 In the data type , It is divided into value type and reference type , quote ...

  9. Unicode Character to string

    /*** * Unicode Character to string * @param str * Unicode character * @return * String * * @author WXW */ public static ...

Random recommendation

  1. bzoj4621: Tc605

    Write down the solution to the problem as required . my DP It's very esoteric ( p. ) miao ( blame ), But it's the same as the standard calculation ( Whatever you do ……) Let's talk about the nature of mystery first . First , In the final sequence , At most one paragraph per number , also , For numbers that appear , Count each paragraph in pairs ...

  2. RankLib Parameter translation

    Write it at the front ,metric2t Index details : NDCG(Normalized discounted cumulative gain) namely DCG/IDCGCG(cumulative gain)DCG(Discou ...

  3. linux php

    ubuntu php -v see php Version number View directory cd / ls apache: If the RPM Package installation , The installation path should be in /etc/httpd Under the table of contents apache The configuration file :/etc/httpd/con ...

  4. Python Study ——struct Modular pack、unpack Example

    he struct module includes functions for converting between strings of bytes and native Python data t ...

  5. java Complete binary tree construction and four traversal methods

    It's basic knowledge , Don't throw it too clean , It took so long to write it today , Remember . There is a complete binary tree as follows : The result of preorder traversal should be :1  2  4  5  3  6  7 The result of middle order traversal should be :4  2  5 ...

  6. Vulnerability Scanning

    1.Vulnerability scanning with Nmap Scripting Engine the Nmap Script Engine provide a alrge number of ...

  7. translate :XtraDB/InnoDB Medium AUTO_INCREMENT Processing mode ( Submitted to MariaDB The official manual )

    This paper is about mariadb The official manual :XtraDB/InnoDB Medium AUTO_INCREMENT How to deal with it . original text :https://mariadb.com/kb/en/auto_increment-han ...

  8. Python3 Overview of Scientific Computing Library

    Python3 Introduction to the common library of scientific computing Numpy Fast data processing library See my blog http://www.cnblogs.com/brightyuxl/p/8981294.html http://www.cnb ...

  9. C# Dapper Simple example

    /// <summary> /// Paging information /// </summary> public class PageInfo<T>     {         /// & ...

  10. ubuntn install python3 And django And pip3

    1.sudo apt-get install python3-pip    install pip3 2.sudo pip3 install django    adopt pip3 install django 3. sudo apt ...