Skip to content

Instantly share code, notes, and snippets.

@learncfinaweek
Created November 20, 2012 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save learncfinaweek/4121432 to your computer and use it in GitHub Desktop.
Save learncfinaweek/4121432 to your computer and use it in GitHub Desktop.
i18n - Hands On 32

In this hands on we will change our locale and update the date and time outputs to change the display based on our locale.

Functions Used: LsdateFormat, LstimeFormat, setLocale

  1. To be able to change the date and time formats based on our locale, you need to update the functions used for date and time output. Open up the /www/blogpost.cfm file in your code editor.
  2. Locate the blogPost.datePosted variable output on or around line 52.
  3. Replace the dateFormat code with the following line of code:
    #LsdateFormat(blogPost.datePosted,'short')#
    
  4. Locate the comment.createdDateTime variable on or around line 72.
  5. Change the dateformat code with the following code:
    #LsdateFormat(comment.createdDateTime,'short')#	
    
  6. Change the timeFormat code with the following code:
    #LstimeFormat(comment.createdDateTime,'medium')#
    
  7. Open up the /www/blog.cfm page in your browser.
  8. Navigate to a blog post and review the date and time output. If you are based in the U.S., you will probably not notice any difference. If you are outside of the U.S., then you will probably see a different date and time format.
  9. To allow everyone to see a change in the formatting, let’s create a temporary page which will change our locale. Create a file called updateLocale.cfm in the /www/ folder.
  10. Open up the /www/updateLocale.cfm file in your code editor.
  11. Add the following line of code:
    <cfset setLocale('English (UK)') /> 
    
  12. Open up the /www/updateLocale.cfm page in your browser. You will not see any output, but the new locale has been set (unless you are in the UK; in that case, you should try a different locale such as English (US) ).
  13. Navigate back to the /www/blog.cfm page and click on a blog post. You should now notice that the date and time formats have changed. The changes might be slight, but they are there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment