Convert UTC string to tdatetime in Delphi

Source: Internet
Author: User

Eg. var TM: string; DT: tdatetime;

TM: = '2017-08-21t09: 11: 21z'; DT: =?

 

Procedure setisotodatetime ( Strdt : String );  
VaR  
// Delphi settings save vars  
Shortdf , Shorttf : String ;  
TS , DS : Char ;  
// Conversion vars  
Dd , TT , Ddtt : Tdatetime ;  
Begin  
// Example datetime test string in ISO format  
Strdt : = '2017-07-06t01: 53: 23z' ;  
 
// Save Delphi settings  
DS : = Dateseparator ;  
TS : = Timeseparator ;  
Shortdf : = Shortdateformat ;  
Shorttf : = Shorttimeformat ;  
 
// Set Delphi settings for string to date/time  
Dateseparator : = '-' ;  
Shortdateformat : = 'Yyyy-mm-dd' ;  
Timeseparator : = ':' ;  
Shorttimeformat : = 'Hh: mm: ss' ;  
 
// Convert test string to datetime  
Try  
 
Dd : = Strtodate ( Copy ( Strdt , 1 , Pos ( 'T' , Strdt )- 1 ) );  
TT : = Strtotime ( Copy ( Strdt , Pos ( 'T' , Strdt ) + 1 , 8 ) );  
Ddtt : = Trunc ( Dd ) + Frac ( TT );  
 
Except  
On Econverterror Do  
Showmessage ( 'Error in converting :' + Strdt );  
End ;  
 
// Restore Delphi settings  
Dateseparator : = DS ;  
Shortdateformat : = Shortdf ;  
Timeseparator : = TS ;  
Shorttimeformat : = Shorttf ;  
 
// Display test string  
Showmessage ( Formatdatetime ( 'Mm/DD/YYYY hh: mm: ss' , Ddtt ) );  
End ;

Http://qc.embarcadero.com/wc/qcmain.aspx? D = 9547

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.