GithubHelp home page GithubHelp logo

jrhizor / jquery.dynamictimezones Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 31 KB

A jQuery plugin that allows developers to show dates and times on their websites which reflect the client's timezone by replacing the contents of an HTML tag with the client's time.

JavaScript 32.66% HTML 67.34%
javascript jquery jquery-plugin jquery-plugins timezones

jquery.dynamictimezones's Introduction

jQuery dynamicTimezones Plugin

This plugin allows developers to show dates and times on their websites which reflect the client's timezone by replacing the contents of an HTML tag with the client's time.

Example

First, include jquery-1.4.2.min.js, phpjs.date.js, and jquery.dynamicTimezones.js within the <head> tags of your page.

<script type="text/javascript" src="jquery-1.4.2.min.js" charset="utf-8"></script>
<script type="text/javascript" src="phpjs.date.js" charset="utf-8"></script>
<script type="text/javascript" src="jquery.dynamicTimezones.js" charset="utf-8"></script>

Then, add a class to the paragraph or div that contains your date.

<p><span class="dtz 1278630213">7:03 EST</span></p>

The dtz class can be any unique identifier for a date of this type. The 1278630213 is the number of seconds from the Linux epoch given by the PHP time() function. Both the timestamp and the the "7:03 EST" should be generated on the server's side. For your $(document).ready function, use the following code. The one parameter .dynamicTimezones() takes is a string formatted like dates displayed with the PHP date() function. For more information on formatting dates, visit http://phpjs.org/functions/date:380.

$(document).ready(function() {
	$('.dtz').dynamicTimezones("g:i");
});

Now, when a client views the page (if they have JavaScript enabled) they will see the date/time represented by the timestamp in their own timezone, not the server's timezone. This can be used with differently formatted dates on the same page by giving alternate class names to the different formats.

jquery.dynamictimezones's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.