CloudStack The time used in the project is UTC Time , What exactly is UTC Time can be Baidu , But the time we need is normal time , So in Guotai Junan development and testing cloud , Synchronous management of virtual machine in synchronous resource management , Need to convert the time format of the virtual machine . Tools are as follows , The key is the time format , The time format is yyyy-MM-dd'T'HH:mm:ss+SSSS.

public static Date utc2LocalDate(String utcTime) {
        String utcTimePatten = "yyyy-MM-dd'T'HH:mm:ss+SSSS";
        SimpleDateFormat sdf = new SimpleDateFormat(utcTimePatten);
        Date dt = null;
        try {
            dt = sdf.parse(utcTime);
        catch (ParseException e) {

return dt;

Test class :

public class TestUtcTime {

     * @param args
     * @return void

public static void main(String[] args) {
        String ts = "2015-04-22T15:58:54+0800";
        Date date = new Date();



Another way is as follows :

public class TestUtc {
    public static void main(String args[]) {
        try {
            String ts = "2015-04-22T15:58:54+0800";
            System.out.println("ts = " + ts);
            ts = ts.replace("Z", " UTC");
            System.out.println("ts = " + ts);
            SimpleDateFormat sdf = new SimpleDateFormat(

Date dt = sdf.parse(ts);

TimeZone tz = sdf.getTimeZone();
            Calendar c = sdf.getCalendar();
            System.out.println("Display name: " + tz.getDisplayName());
        catch (ParseException pe) {
            System.out.println("Error offset: " + pe.getErrorOffset());

private static String getString(Calendar c) {
        StringBuffer result = new StringBuffer();
        result.append((c.get(Calendar.MONTH) + 1));
        result.append(" ");
        return result.toString();


Reprint please indicate :

CloudStack In the cloud machine UTC More articles on time to local time

  1. c# in WMI Change the date and time in to local time

    The value obtained :CreationDate:20170122084915 .713600+480 turn :   var objQuery = new ObjectQuery("select * from ...

  2. take UTC Date string to local time string , Such as @"yyyy-MM-dd'T'HH:mm:ssZ" Convert to local time

    Thanks to the apple store app 24 It's going to be unstable within hours , Updating reminders can fall into a dead circle , Update reminder needs 24 Pop up in hours , We need to convert the online time returned by apple to the local time, so we wrote the following method : // take UTC Date string to local time string // Input ...

  3. utc Time 、 Local time and timestamp conversion

    1. The concept of timestamps See Encyclopedia for the definition of time stamp unix Time stamp , Note that the timestamp is the current time minus UTC Time (1970.1.1) The difference in seconds at zero , Independent of the time zone of the current system , At the same time, no matter in any time zone, the time stamp obtained is one ...

  4. Python: Handle mongodb file , How to let UTC Time to local time ?

    Store data to MongoDB Database time , Generally, we will add a time to update the data update_time. At this moment in python In the code use datetime Module to get the current system time , But to MongoDB Database time , Storage ...

  5. Python How to put a UTC Time to local time

    demand : take 20141126010101 Format UTC Time to local time . After searching the Internet for a long time, I didn't find a perfect solution . Some refer to third-party libraries , This requires the installation of third-party software in the existing network . This is absolutely impossible . Because the real environment is different ...

  6. UTC、GTC Time and local time

    1. problem For those with Windows and Linux The machine of the system , Get into Windows The time and Linux atypism ,Linux Time ratio in Windows advance 8 Hours . 2. resolvent modify /etc/default/r ...

  7. [ Re posting ]UTC Time 、GMT Time 、 Local time 、Unix Time stamp

    UTC Time .GMT Time . Local time .Unix Time stamp quote : ...

  8. UTC Time to local time

    UTC Time to local time DATEADD(hour, DATEDIFF(hour,GETUTCDATE(),GETDATE()), OrderDate) <'2015-02-02' DECLARE ...

  9. About UTC Time and local time

    A collection of classes Publics  Local time and UTC Time conversion UCT Time = Local time -8    Local time is shorter than UTC Fast time 8 Hours element-ui On the date selector of   The selected time shows the local time     But it's true ...

Random recommendation

  1. C++ Multithread synchronization in development process lock The implementation of the

    Multithreading is often used in program development , Multithreading is always closely related to locks , The following is a detailed description of how to C++ Several methods of custom lock in the process of program development . 1. Here's a piece of code to show how to use Mutex Realize the function of lock (window p ...

  2. selenium Find dynamic iframe Of name

    WebElement frame1 = driver.findElement(By.xpath("/html/body/div[9]/div[2]/div/iframe"));dr ...

  3. android115 Custom control

    Layout : <RelativeLayout xmlns:android="" xmlns:to ...

  4. Hive Common operations of data import and export

    One .Hive Data import and export 1.hive Export data A lot of times , We are hive In the implementation of select sentence , Want to save the final result to a local file or to hdfs In the system or in a new table ,hive Provides convenient keywords ...

  5. Use sql Statement create table 、 Modify table 、 Add columns, etc

    1. Create table : CREATE TABLE Student information (    Student number  varchar(14) IDENTITY(1,1) PRIMARY KEY,    full name varchar(8) UNIQUE NOT ...

  6. css Style sheets 1 2017-03-11

    Style sheets DIV + CSS One .        Classification of style sheets The following are all based on div For example, labels , It can be replaced with other labels 1.  Inline style sheets Format : style=" attribute 1: Property value 1: attribute 2: Property value 2: attribute 3: ...

  7. Python- Class (property)

    What are features property property It's a special property , Access to it will perform a function ( function ) Then return the value Patients with a :BMI Index (bmi It's calculated , But it obviously sounds like an attribute rather than a method , If we make it into a ...

  8. Delphi-Cross-Socket

    Delphi-Cross-Socket GITHUB: # Delphi Cross platform Socket Communication library ...

  9. android Development Notes Volley (1)

    1. volley An introduction to the Volley is an HTTP library that makes networking for Android apps easier and most import ...

  10. SpringMvc visit Controller Get rid of do

    It just needs to be modified web.xml file <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xs ...