0

i'm use this code but i don't no how can show only uae standard time in all country.

<html>
<head></head>

<body>
<script>

var mydate=new Date()
var year=mydate.getYear()

if (year < 1000)
    year+=1900

var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()

if (daym<10)
    daym="0"+daym

var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday",
                        "Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June",
                        "July","August","September","October","November","December")

document.write(dayarray[day]+", "+montharray[month]+" "+daym+", "+year)

</script>
</body>
</html>

this is my code please suggest me right answer thanks.

see image for detail

Waseem Khan
  • 9
  • 1
  • 7

3 Answers3

2

try this in PHP, use date_default_timezone_set function, it's easy and simple

<?php
    date_default_timezone_set('Asia/Dubai');
    echo "The time is " . date('d-m-Y H:i:s');
?>

if you want to use in java script than try this

<script>
    var d = new Date();
    var localTime = d.getTime();
    var localOffset = d.getTimezoneOffset() * 60000;
    var utc = localTime + localOffset;
    var offset = 4;    //UTC of Dubai is +04.00
    var dubai = utc + (3600000*offset);
    var nd = new Date(dubai); 
    alert("Dubai time is " + nd.toLocaleString() + "<br>");
</script>
Kashif Latif
  • 657
  • 3
  • 15
  • 29
0

To get the local time of UAE you can try this code:

var d = new Date();
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
var uaeDate = new Date(utc + (3600000*4)); // 4 is the offset of UAE

you can search offset of any region on google. Further you can parse date in any format.

Check this link.. There are many alternatives in this post for converting date to any timezone. check and see what works best for you...

Convert date to another timezone in JavaScript

Community
  • 1
  • 1
Sachin
  • 1,208
  • 1
  • 10
  • 20
  • ok thanks @Sachin i try but i have use only uae timezoon in my website and show all country this time. – Waseem Khan Jan 06 '16 at 12:31
  • Note that this only works because the UAE do not have daylight savings time. This would definitely not apply to places with DST. – jcaron Jan 06 '16 at 13:35
  • write `console.log(uaeDate)` in browser console after executing above code @WaseemKhan – Sachin Jan 06 '16 at 13:45
0

Even though the UAE has a single timezone and no daylight savings time, so tricks involving adding a UTC offset can work, it is probably better to use more generic solutions.

You should probably use moment.js for generic date manipulation and formatting and its companion moment timezone for any timezone-related tasks.

jcaron
  • 17,302
  • 6
  • 32
  • 46
  • thanks @jcaron i have update this question and upload image please check, then suggest me i have show DD/YYYY/MM this cequence. – Waseem Khan Jan 06 '16 at 13:50