Object.extend(Date.prototype, {
strftime: function(format) {
var day = this.getUTCDay(), month = this.getUTCMonth();
var hours = this.getUTCHours(), minutes = this.getUTCMinutes();
function pad(num) { return num.toPaddedString(2); };
return format.gsub(/\%([aAbBcdDHiImMpSwyY])/, function(part) {
switch(part[1]) {
case 'a': return $w("Sun Mon Tue Wed Thu Fri Sat")[day]; break;
case 'A': return $w("Sunday Monday Tuesday Wednesday Thursday
Friday Saturday")[day]; break;
case 'b': return $w("Jan Feb Mar Apr May Jun Jul Aug Sep Oct
Nov Dec")[month]; break;
case 'B': return $w("January February March April May June July
August September October November December")
[month]; break;
case 'c': return this.toString(); break;
case 'd': return this.getUTCDate(); break;
case 'D': return pad(this.getUTCDate()); break;
case 'H': return pad(hours); break;
case 'i': return (hours === 12 || hours === 0) ? 12 :
(hours + 12) % 12; break;
case 'I': return pad((hours === 12 || hours === 0) ? 12 :
(hours + 12) % 12); break;
case 'm': return pad(month + 1); break;
case 'M': return pad(minutes); break;
case 'p': return hours > 11 ? 'PM' : 'AM'; break;
case 'S': return pad(this.getUTCSeconds()); break;
case 'w': return day; break;
case 'y': return pad(this.getUTCFullYear() % 100); break;
case 'Y': return this.getUTCFullYear().toString(); break;
}
}.bind(this));
}
});
http://alternateidea.com/blog/articles/2008/2/8/a-strftime-for-prototype
Tuesday, October 28, 2008
A strftime for Prototype
Labels:
JavaScript,
plugin,
Prototype
Subscribe to:
Post Comments (Atom)
Bookmarks
Generators
- .NET Buttons
- 3D-box maker
- A CSS sticky footer
- A web-based graphics effects generator
- Activity indicators
- Ajax loader
- ASCII art generator
- Attack Ad Generator
- Badge shape creation
- Binary File to Base64 Encoder / Translator
- Browsershots makes screenshots of your web design in different browsers
- Button generator
- Buttonator 2.0
- Color Palette
- Color schemer
- Color Themes
- Colorsuckr: Create color schemes based on photos for use in your artwork & designs
- Create DOM Statements
- CSS Organizer
- CSS Sprite Generator
- CSS Sprites
- CSS Type Set
- Digital Post It Note Generator
- Easily create web forms and fillable PDF documents to embed on your websites
- egoSurf
- Favicon Editor
- Favicon generator
- Flash website generator
- Flip Title
- Flipping characters with UNICODE
- Form Builder
- Free Footer online tools for webmasters and bloggers.
- Free templates
- FreshGenerator
- Genfavicon
- hCalendar Creator
- HTML form builder
- HTML to Javascript DOM converter
- Image Mosaic Generator
- Image reflection generator
- img2json
- JSON Visualization
- Login form design patterns
- Logo creator
- Lorem Ipsum Generator
- LovelyCharts
- Markup Generator
- Mockup Generator
- Online Background Generators
- PatternTap
- Pixenate Photo Editor
- Preloaders
- Printable world map
- punypng
- Regular Expressions
- RoundedCornr
- SingleFunction
- Spam proof
- Stripe designer
- Stripe generator 2.0
- Tabs generator
- Tartan Maker. The new trendsetting application for cool designers
- Test Everithing
- Text 2 PNG
- The Color Wizard 3.0
- tinyarro.ws: Shortest URLs on Earth
- Web 2.0 Badges
- Web UI Development
- Website Ribbon
- wwwsqldesigner
- Xenocode Browser Sandbox - Run any browser from the web
- XHTML/CSS Markup generator
Library
- 12 Steps to MooTools Mastery
- AJAX APIs Playground
- Best Tech Videos
- CSS Tricks
- FileFormat.info
- Grafpedia
- IT Ebooks :: Videos
- Learning Dojo
- Linux Software Repositories
- NET Books
- PDFCHM
- Rails Engines
- Rails Illustrated
- Rails Metal: a micro-framework with the power of Rails: \m/
- Rails Podcast
- Rails Screencasts
- RegExLib
- Ruby On Rails Security Guide
- Ruby-GNOME2 Project Website
- Rubyology
- RubyPlus Video
- Scaling Rails
- Scripteka
- This Week in Django
- WebAppers
No comments:
Post a Comment