{"id":1863,"date":"2010-11-15T10:24:59","date_gmt":"2010-11-15T10:24:59","guid":{"rendered":"http:\/\/mts-help.nick.php.dev\/after_sale_support\/Working_with_Flash\/Advanced\/article2.html"},"modified":"2015-09-17T07:35:32","modified_gmt":"2015-09-17T11:35:32","slug":"current-time-and-date-flash","status":"publish","type":"post","link":"https:\/\/www.templatemonster.com\/help\/current-time-and-date-flash.html","title":{"rendered":"Current time and date in Flash"},"content":{"rendered":"<span class=\"question\">Q:<\/span> <span class=\"question_text\">How can I make my Flash site display current time and date?<\/span>\r\n\r\n<span class=\"answer\">A:<\/span> <span class=\"answer_text\">You can do it with the help of the Date() class available in Action Script. This class has all the necessary methods to retrieve full information about the current time. Before using these methods you need to create a date <span style=\"font-weight: bold;\">&#8220;object&#8221;<\/span> in the class, this is because the methods are not static and they can only be applied to a single object. To create a Date object please, use the following syntax: <\/span>\r\n<pre class=\"brush:as3\">var current_time = new Date();\r\n\r\n<\/pre>\r\nAfter that you can use different methods for this object getDate(), getDay(), getFullYear(), getHours(), getMilliseconds(), getMonth() and so on). Use Flash Help documentation to learn more about the Date() class and its methods.\r\nFor example:\r\n<pre class=\"brush:as3\">current_time.getMonth();\r\ncurrent_time.getFullYear();\r\n\r\n<\/pre>\r\nNote: You can retrieve both your operating system time and universal time &#8211; UTC (known before as GMT Greenwich mean time). To display UTC time you should use the methods that have &#8220;UTC&#8221; in their names (getUTCDate(), getUTCDay(), getUTCFullYear(), getUTCHours(), getUTCMilliseconds(), getUTCMonth() and so on)\r\n<div id=\"demo\" style=\"border: 1px solid black; background-color: #cccccc; width: 780px; display: none; height: 601px;\"><object id=\"current_time_and_date_in_Flash.files\/time\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"776\" height=\"598\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"quality\" value=\"high\" \/><param name=\"bgcolor\" value=\"#FFFFFF\" \/><param name=\"src\" value=\"time_demo.htm\" \/><embed id=\"current_time_and_date_in_Flash.files\/time\" type=\"application\/x-shockwave-flash\" width=\"776\" height=\"598\" src=\"time_demo.htm\" bgcolor=\"#FFFFFF\" quality=\"high\"> <\/embed><\/object><\/div>\r\n<span style=\"font-weight: bold;\">See also:<\/span>\r\n\r\n<a class=\"video\" href=\"\/help\/files\/Flash\/How_to_set_up_current_time_and_date.swf\">How to set up the current time and date demo movie<\/a>\r\n\r\nHere&#8217;s the code used in the demo movie:\r\n<pre class=\"brush:as3\">var today = new Date();\r\nvar minutes = today.getMinutes();\r\nvar hours = today.getHours();\r\nvar dat = today.getDate();\r\nvar month = today.getMonth()+1;\r\nvar year = today.getFullYear();\r\nvar dayN = today.getDay();\r\nswitch (dayN) {\r\ncase 0 :\r\nday = \"Sunday\";\r\nbreak;\r\ncase 1 :\r\nday = \"Monday\";\r\nbreak;\r\ncase 2 :\r\nday = \"Tuesday\";\r\nbreak;\r\ncase 3 :\r\nday = \"Wednesday\";\r\nbreak;\r\ncase 4 :\r\nday = \"Thursday\";\r\nbreak;\r\ncase 5 :\r\nday = \"Friday\";\r\nbreak;\r\ncase 6 :\r\nday = \"Saturday\";\r\nbreak;\r\n}\r\nif (hours&gt;12) {\r\nc_time = (hours-12);\r\nAM_PM = \"PM\";\r\n}\r\nif (hours==12){\r\nc_time = 12;\r\nAM_PM = \"PM\";\r\n}\r\nif (hours&lt;12){\r\nc_time = hours;\r\nAM_PM = \"AM\";\r\n}\r\nif (hours==0){\r\nc_time = 12;\r\nAM_PM = \"AM\";\r\n}\r\nif (minutes&lt;10) {\r\nis_zero_min = \"0\";\r\n} else {\r\nis_zero_min = \"\";\r\n}\r\nif (dat&lt;10) {\r\nis_zero_dat = \"0\";\r\n} else {\r\nis_zero_dat = \"\";\r\n}\r\nif (month&lt;10) {\r\nis_zero_mon = \"0\";\r\n} else {\r\nis_zero_mon = \"\";\r\n}\r\noutput = c_time+\":\"+is_zero_min+minutes+\" \"+AM_PM+\" \"+day+\" \"+is_zero_dat+dat+\".\"+is_zero_mon+month+\".\"+year;<\/pre>","protected":false},"excerpt":{"rendered":"<p>Q: How can I make my Flash site display current time and date? A: You can do it with the help of the Date() class available in Action Script. This class has all the necessary methods to retrieve full information about the current time. Before using these methods you need to create a date &#8220;object&#8221; [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[355,279],"tags":[486],"_links":{"self":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/1863"}],"collection":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/comments?post=1863"}],"version-history":[{"count":0,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/1863\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media?parent=1863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/categories?post=1863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/tags?post=1863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}