# ADO \<\> Jira Cloud: Date time sync

**URL:** https://community.exalate.com/t/ado-jira-cloud-date-time-sync/5800
**Category:** Script Library
**Created:** [November 17, 2024, 1:50pm UTC](https://community.exalate.com/t/ado-jira-cloud-date-time-sync/5800 "2024-11-17T13:50:13Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![francis](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/francis/32/312_2.png) [@francis](https://community.exalate.com/u/francis)
#### Post date: [November 17, 2024, 1:50pm UTC](https://community.exalate.com/t/ado-jira-cloud-date-time-sync/5800/1 "2024-11-17T13:50:13Z")

</div>

If your Jira and ADO are hosted in different time zones, and you need to manipulate the date/time fields so that the same date is kept, here is how we do it. Let us assume:

- “Due Date” and “Start Date” are custom date/time fields in ADO
- “Start date” is a custom Date field in Jira
- Due is the standard due date field in Jira
- We would like to add 5 hours to the Jira timestamp when they are received in ADO
- We would like to subtract 3 hours to the ADO timestamp when they are received in Jira (just as an example)

#### Jira Outgoing Script

```
replica.customFields."Start date" = issue.customFields."Start date"
replica.due = issue.due

```

#### Jira Incoming Script

```
import java.text.SimpleDateFormat
import java.text.DateFormat
import java.util.Calendar
import java.util.Date

def datePattern = "yyyy-MM-dd HH:mm:ss";
DateFormat formatter = new SimpleDateFormat(datePattern);
dateString = replica."start"
dateString = dateString.replaceAll("T"," ").trim();
dateString = dateString.replaceAll("Z"," ").trim();  
date = formatter.parse(dateString);
def timestamp = date.time
Calendar calendar = Calendar.getInstance()
calendar.timeInMillis = timestamp
calendar.add(Calendar.HOUR_OF_DAY, -5)
def updatedTimestamp = calendar.timeInMillis
issue.customFields."Start date".value = updatedTimestamp

dateString = replica."duedate"
dateString = dateString.replaceAll("T"," ").trim();
dateString = dateString.replaceAll("Z"," ").trim();  
date = formatter.parse(dateString);
timestamp = date.time
calendar.timeInMillis = timestamp
calendar.add(Calendar.HOUR_OF_DAY, -5)
issue.due = calendar.getTime()

```

#### ADO Outgoing Script

```
replica."start" = workItem."Microsoft.VSTS.Scheduling.StartDate"
replica."duedate" = workItem."Microsoft.VSTS.Scheduling.DueDate"

```

#### ADO Incoming Script

```
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date

def convertJiraTimeToAdoTime(String dateString){
    if(dateString == null) return 
    String inputFormat = "yyyy-MM-dd HH:mm:ss.S"
    String outputFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"

    // Create SimpleDateFormat objects for the input and output formats
    SimpleDateFormat inputDateFormat = new SimpleDateFormat(inputFormat)
    SimpleDateFormat outputDateFormat = new SimpleDateFormat(outputFormat)

    // Parse the input date string into a Date object
    Date date = inputDateFormat.parse(dateString)

    def timestamp = date.time
    Calendar calendar = Calendar.getInstance()
    calendar.timeInMillis = timestamp
    calendar.add(Calendar.HOUR_OF_DAY, 5)
    def updatedTimestamp = calendar.timeInMillis

    // Convert the Date object into the output format
    return outputDateFormat.format(updatedTimestamp) // String
}

// does not set the field
String inputDateString = replica.customFields."Start date"?.value 
workItem."Microsoft.VSTS.Scheduling.StartDate" = convertJiraTimeToAdoTime(inputDateString)
inputDateString = replica.due 
workItem."Microsoft.VSTS.Scheduling.DueDate" = convertJiraTimeToAdoTime(inputDateString)

```
