Home > apex > How to convert a text to dateTime

How to convert a text to dateTime

August 7Hits:1
Advertisement

How can i convert a string like this Wed Aug 07 04:30:00 GMT 2013 to a dateTime value?

Answers

Map <String, Integer> monthNames = new Map <String, Integer> {'Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, 'May'=>5, 'Jun'=>6, 'Jul'=>7, 'Aug'=>8, 'Sep'=>9, 'Oct'=>10, 'Nov'=>11, 'Dec'=>12};
List <String> stringParts = 'Wed Aug 07 04:30:00 GMT 2013'.split(' ');
List <String> timeParts = stringParts[3].split(':');

DateTime yourDateVariable = DateTime.newInstanceGmt(Integer.valueOf(stringParts[5]), monthNames.get(stringParts[1]), Integer.valueOf(stringParts[2]), Integer.valueOf(timeParts[0]), Integer.valueOf(timeParts[1]), Integer.valueOf(timeParts[2]));

Use DateTime parse method: e.g.;

Datetime dt = DateTime.parse('10/14/2011 11:46 AM');

will return date instance of String.

or try

String stringDate = '2013-10-05 20:03:20';

Datetime myDate = datetime.valueOf(stringDate);

Related Articles

  • How to convert a text to dateTimeAugust 7

    How can i convert a string like this Wed Aug 07 04:30:00 GMT 2013 to a dateTime value? --------------Solutions------------- Map <String, Integer> monthNames = new Map <String, Integer> {'Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, 'May'

  • Mac OSX Numbers - Convert text to datetime

    Mac OSX Numbers - Convert text to datetimeJanuary 23

    I am using Numbers on a Mac. I have a CSV file which contains numerous dates in the format MM/DD/YYYY. I need to convert these dates into datetime format for insertion into a MySQL table. How do I convert strings of date format MM/DD/YYYY to datetime

  • Convert T01D163DE49AED860 to a datetime?February 11

    In Word MRU list in Registry, it seems like the datetime is stored like T01D163DE49AED860. Any idea how I convert this to a datetime? --------------Solutions------------- This a Hex registry value. The key is located here: HKLM\SOFTWARE\Microsoft\Win

  • How to stop Exchange 2007 from automatically converting plain text emails to HTML?May 20

    this.. nice.. exchange server converts my text/plain messages from text to html and messes them up, just because it detects html somewhere in the body. how can i stop him from doing so? edit: i am looking for a server side fix - this is affecting aut

  • How to convert all text to lowercase in vimJuly 9

    How do you convert all text in vim to lowercase? Is it even possible? --------------Solutions------------- If you really mean small caps, then no, that is not possible – just as it isn't possible to convert text to bold or italic in any text editor (

  • Commandline tool to convert between text formats? August 21

    How can I batch-convert files in a directory for their encoding (e.g. ANSI->UTF-8) with a command or tool? For single files an editor helps, but how to do the mass files job? --------------Solutions------------- Cygwin or GnuWin32 provide Unix tools

  • How to convert selected text to sentence case?January 9

    How to convert selected text to sentence case? like How Are YOU to this How are you --------------Solutions------------- ^!v:: clipboard:=ClipboardAll StringLower, string, clipboard StringTrimLeft, output, string, 1 StringLeft, FirstChar, string, 1 S

  • Taking screenshot and converting captured text into selectable text?August 30

    In Snaggit it has a feature that let's you take a screenshot and if there are texts on screen it converts the text into selectable text (somehow) so you can copy and paste the text into a text editor for example. Is there any free software that can d

  • How can I convert Point Text to Paragraph and Vice Versa in photoshop

    How can I convert Point Text to Paragraph and Vice Versa in photoshop December 25

    Possible Duplicate: Turning a text "string" into a text "block" in Photoshop CS6? Here we know that there are two texting modes in PSE - "single-line" and "paragraph". The problem is how to convert point text to par

  • Convert Windows text file to Ubuntu text fileFebruary 12

    I am trying to port a C++ program from Windows to Ubuntu . In Ubuntu environment , My program reads a text file which was created in Windows , however it appears the Carriage Return is affecting the reading of the file in Ubuntu environment , therefo

  • texstudio scripting:converting selected textMarch 14

    There is not ToUppercase ToLowercase function which convers text in my language from so called small letters to capital letters. how can i loop char by char in selected text in texstudio to convert selected text? example: from_array={'ა','ბ','გ','დ'}

  • Is it possible to convert a text that's in the form of a changelog from oldest-first into newest-first, using vim?April 23

    Is it possible to convert a text that's in the form of a changelog into newest-first, using vim? It's like this: version 1.0 multi_line description for 1.0 version 1.01 multi_line description for 1.01 etc and I want to convert it into version 1.90 mu

  • How to convert date string to DateTime type without GMT?May 18

    I have a string = '11/6/2014 '. I want to convert it to a DateTime DateTime dt = DateTime.parse('11/6/2014'); this causes an error, so I run the code below and it does work: DateTime dt = DateTime.parse('11/6/2014 12:00 AM'); What i get is '11/6/2014

  • Convert all text from uppercase to lowercase and vice versa?June 8

    My question is how can I convert all text from uppercase to lowercase and vice versa? That is to change the cases of all the letters. It has to be done with a sed replacement somehow. --------------Solutions------------- Here is a straight way in sed

  • Preserving table borders and shades while converting to text in word 2010August 18

    I am trying to create a word 2010 template to display some data to user when he creates a new document based on it. As such, I need to display a table in the document. I have created the document template, and it uses string with tab separators. Prob

  • how to convert the text into timing for subtitleSeptember 13

    I have a video which is take 6 hours and 31 minutes which I want to get the subtitle from youtube but i couldn't be able to do as they are take the video for 1 hour only. I have uploaded each video of each hour on youtube to get subtitles. However, I

  • How to convert all text in PDF to image

    How to convert all text in PDF to imageJanuary 23

    Preamble I have been writing lectures in the institute on notebook. Others wrote them with pen and paper (Don't know how to say correctly in English, but I think it is understandable). Now we are to show our lectures to teacher. Half of my groupmates

  • Is it possible to convert a text date to one stored as a date in Excel?March 14

    I have dates stored as text in the following format: Mar 10, 2015 I want to convert it to a value stored as a date and display it formatted as yyyy-mm-dd: 2015-03-10 I initially tried to use the text to columns feature and parsed all the date compone

  • How to convert formatted text in a Powerpoint table cell to HTMLApril 18

    I want to convert a table in a Powerpoint slide to HTML. I know how to put in the table tags, but cannot work out how to convert formatted text inside the table cells to HTML. So, for example, how can I convert "This is a cell with bold text" to

  • How can I convert climatic text data to raster in QGIS and ArcGIS?May 19

    I have been provided with text (*txt) formatted, tabular climatic data. How can I convert climatic text data to raster in QGIS and ArcGIS? In addition to tabular data, the following information is provided ncols 480 nrows 600 xllcorner -20 yllcorner

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.322 s.