Other @ force2be时间/时区转换

//http://www.force2b.net/index.php/2010/08/date-time-and-timezone-handling-in-apex/

/* **********************************************************************************************
* TimeConversions Class
* Created by: Michael Smith/Force2b, 04/06/2010
*
************************************************************************************************ */
global class TimeConversions {
   
   /* -------------------------------------------------------------------------------------
   * Returns an Integer  of the Timezone Offset from Eastern Time for the
   * currently logged in user
   *
   * This is used to convert the String DateTime (that is in Eastern Time) into a
   * DateTime value in SalesForce. The default behavior of SFC converts the string into
   * a local datetime value, but we need to get into Eastern Time.
   * ------------------------------------------------------------------------------------- */
   public Integer getCurrentUserTZOffsetFromEastern() {
      
      Map<String, Integer[]> tzSIDKeys = getTZSidKeys();
      
      User user = [SELECT ID, TimeZoneSidKey FROM User WHERE ID = :UserInfo.getUserId() LIMIT 1];
      
      Date[] dstDatesNow = getDSTDates(System.Today().year());
      Integer UsersTZOffset = 0;
      
      if (tzSIDKeys.get(user.TimeZoneSidKey) != null) {
         // Get the base timezone offset from GMT for the user
         if (System.Today() >= dstDatesNow[0] && System.Today() <= dstDatesNow[1]) UsersTZOffset = tzSIDKeys.get(user.TimeZoneSidKey)[1];
         else UsersTZOffset = tzSIDKeys.get(user.TimeZoneSidKey)[0];
         system.debug(LoggingLevel.Error, 'Base TimeZone for Current User=' + user.TimeZoneSidKey + '/' + UsersTZOffset );
         
         // Now make it a timezone offset from EASTERN time
         Integer EasternTZOffset = 0;
         if (System.Today() >= dstDatesNow[0] && System.Today() <= dstDatesNow[1]) EasternTZOffset = tzSIDKeys.get('America/New_York')[1];
         else EasternTZOffset = tzSIDKeys.get('America/New_York')[0];
         UsersTZOffset = Math.abs(EasternTZOffset) - Math.abs(UsersTZOffset);
         system.debug(LoggingLevel.Error, 'TimeZone Offset to Eastern Time=' + UsersTZOffset );
      }
      return UsersTZOffset ;
   }
   
   /* -------------------------------------------------------------------------------------
   * Returns a String Collection of the Timezone Codes based on the Timezone Offset Passed
   * for the date passed.
   *
   * Based on a table from: http://en.wikipedia.org/wiki/Zone.tab
   *
   * getTimeZoneCode[0] = Display Text (ex: EDT)
   * getTimeZoneCode[1] = DateTime.Format() parameter (ex: America/New_York)
   * ------------------------------------------------------------------------------------- */
   public string[] getTimeZoneCode(Integer tzOffset, Date theDate, Boolean isDSTObserved) {
      Date[] dstDates = getDSTDates(theDate.year()); // [0]=startDate, [1]=endDate
      boolean isDSTOn = (theDate >= dstDates[0] && theDate <= dstDates[1]);
      
      if (tzOffset == 0) return new String[]{' GMT', 'Europe/London' };
      else if (tzOffset == 4) return new String[]{' AST (UTC-04)', 'America/Puerto_Rico' };
      else if (tzOffset == 5 && isDSTOn && isDSTObserved) return new String[]{' EDT (UTC-04)', 'America/New_York' };
      else if (tzOffset == 5) return new String[]{' EST (UTC-05)', 'America/New_York' };
      else if (tzOffset == 6 && isDSTOn && isDSTObserved) return new String[]{' CDT (UTC-05)', 'America/Chicago' };
      else if (tzOffset == 6) return new String[]{' CST (UTC-06)', 'America/Chicago' };
      else if (tzOffset == 7 && !isDSTObserved)         return new String[]{' MST (UTC-07)', 'America/Phoenix' };
      else if (tzOffset == 7 && isDSTOn && isDSTObserved) return new String[]{' MDT (UTC-06)', 'America/Denver' };
      else if (tzOffset == 7) return new String[]{' MST (UTC-07)', 'America/Denver' };
      else if (tzOffset == 8 && isDSTOn && isDSTObserved) return new String[]{' PDT (UTC-07)', 'America/Los_Angeles' };
      else if (tzOffset == 8) return new String[]{' PST (UTC-08)', 'America/Los_Angeles' };
      else if (tzOffset == 9 && isDSTOn && isDSTObserved) return new String[]{' AKDT (UTC-08)', 'America/Anchorage' };
      else if (tzOffset == 9) return new String[]{' AKST (UTC-09)', 'America/Anchorage' };
      else if (tzOffset == 10 && !isDSTObserved)        return new String[]{' HST (UTC-10)', 'Pacific/Honolulu' };
      else if (tzOffset == 10 && isDSTOn && isDSTObserved) return new String[]{' HDT (UTC-09)', 'America/Adak' };
      else if (tzOffset == 10) return new String[]{' HST (UTC-10)', 'America/Adak' };
      else if (tzOffset == 11) return new String[]{' HST (UTC-10)', 'Pacific/Pago_Pago' };
      else return new String[]{' UTC-' + tzOffset, 'GMT' };
   }
   
   /* -------------------------------------------------------------------------------------
   * Returns a date Collection of Start/End dates for US Daylight Saving Time
   * for the specified year.
   *
   * Based on code from: http://www.webexhibits.org/daylightsaving/b2.html
   * ------------------------------------------------------------------------------------- */
   public Date[] getDSTDates(Integer theYear) {
      Long thisYear;
      Long AprilDate;
      Long OctoberDate;
      Long MarchDate;
      Long NovemberDate;
      Long longSeven = 7;
      thisYear = Math.round(theYear);
      
      AprilDate = Math.mod(2+6 * thisYear - Math.floor(thisYear / 4).longValue(), longSeven) + 1;
      OctoberDate=  Math.mod(31-( Math.floor(thisYear * 5 / 4).longValue() + 1), longSeven);
      
      MarchDate = 14 - Math.mod(Math.floor(1 + thisYear * 5 / 4).LongValue(), longSeven);
      NovemberDate = 7 - Math.mod(Math.floor (1 + thisYear * 5 / 4).LongValue(), longSeven);
      
      string startDate = (thisYear > 2006 ? ('03/'+MarchDate) : ('04/'+AprilDate)) + '/' + thisYear;
      string endDate = (thisYear > 2006 ? ('11/'+NovemberDate):('10/'+OctoberDate))+ '/' + thisYear;
      
      Date[] rtnDates = new List<Date>();
      rtnDates.add(Date.parse(startDate));
      rtnDates.add(Date.parse(endDate));
      return rtnDates;
   }
   
   public Map<String, Integer[]> getTZSidKeys() {
      Map<String, Integer[]> tzSIDKeys = new Map<String, Integer[]>();
      tzSIDKeys.put('America/Adak', new Integer[]{-10, -9});
      tzSIDKeys.put('America/Anchorage', new Integer[]{-9, -8});
      tzSIDKeys.put('America/Chicago', new Integer[]{-6, -5});
      tzSIDKeys.put('America/Denver', new Integer[]{-7, -6});
      tzSIDKeys.put('America/Detroit', new Integer[]{-5, -4});
      tzSIDKeys.put('America/Halifax', new Integer[]{-4, -3});
      tzSIDKeys.put('America/Indianapolis', new Integer[]{-5, -4});
      tzSIDKeys.put('America/Los_Angeles', new Integer[]{-8, -7});
      tzSIDKeys.put('America/Montreal', new Integer[]{-5, -4});
      tzSIDKeys.put('America/New_York', new Integer[]{-5, -4});
      tzSIDKeys.put('America/Panama', new Integer[]{-5, -5});
      tzSIDKeys.put('America/Phoenix', new Integer[]{-7, -7});
      tzSIDKeys.put('America/Puerto_Rico', new Integer[]{-4, -4});
      tzSIDKeys.put('America/Toronto', new Integer[]{-5, -4});
      tzSIDKeys.put('America/Vancouver', new Integer[]{-8, -7});
      tzSIDKeys.put('Europe/London', new Integer[]{0, 1});
      tzSIDKeys.put('Pacific/Honolulu', new Integer[]{-10, -10});
      tzSIDKeys.put('Pacific/Pago_Pago', new Integer[]{-11, -11});
      
      return tzSIDKeys;
   }
}

JavaScript sharepoint:使用Javascript从任何页面获取顶级Style-Library网址

var vidpath = String(window.location).split('/sites/')[0] + "/" + String(window.location).split('/sites/')[1].split('/')[0] + "/" + "Style%20Library/Lilly/images/";

jQuery 文本框占位符

if($(input).val() == ""){
	$(input).val("Search Here...");
}

$(input).focus(function(){
	if($(input).val() == "Search Here..."){
		$(this).val("");
	}
});

$(input).blur(function(){
	if($(input).val() == ""){
		$(input).val("Search Here...");
	}
});

PHP 缩小和组合CSS文件

/*

  USING THIS FILE

  1. Add the CSS files you want included to the $file array. */

  $file[] = 'reset.css';
  $file[] = 'typography.css';
  $file[] = 'design.css';

/*
  2. Save this file.

  3. Point your HTML files to this script, eg.
     <link rel="stylesheet" href="/this-file.php" />

  4. Save the HTML file and refresh browser.

*/

header('Content-type: text/css; Charset=utf-8');

function minifyCSS($f)
{
  return preg_replace(array('/\/\*[\s\S]*?\*\//','/\s*([;:{},>+])\s*/',
  '/;}/','/\r?\n/'),array('','\1','}',''),file_get_contents($f));
}
foreach ($file as $name)
{
  if (file_exists($name))
  {
    echo minifyCSS($name);
  }
}

jQuery 使用密码字段切换文本字段(在焦点上)

//src: http://www.electrictoolbox.com/jquery-toggle-between-password-text-field/

$(document).ready(function () {
  $('#password-clear').show();
  $('#password-password').hide();
		
  $('#password-clear').focus(function() {
    $('#password-clear').hide();
    $('#password-password').show();
    $('#password-password').focus();
  });
  $('#password-password').blur(function() {
    if($('#password-password').val() == '') {
      $('#password-clear').show();
      $('#password-password').hide();
    }
  });
});

---

#password-clear {
    display: none;
}

----

<input id="password-clear" class="form-text default-value" type="text" value="Type your password" autocomplete="off" />
<input id="password-password" class="form-text default-value" type="password" name="password" value="" autocomplete="off" />

jQuery 使用jQuery更改焦点上的默认文本值

//http://www.electrictoolbox.com/jquery-change-default-value-on-focus/

$(document).ready(function() {

$('.default-value').each(function() {
    var default_value = this.value;
    $(this).css('color', '#666'); // this could be in the style sheet instead
    $(this).focus(function() {
        if(this.value == default_value) {
            this.value = '';
            $(this).css('color', '#333');
        }
    });
    $(this).blur(function() {
        if(this.value == '') {
            $(this).css('color', '#666');
            this.value = default_value;
        }
    });
});

});

---

<input type="text" class="default-value" size="30" value="Enter keywords here" />
<input type="text" class="default-value" size="30" value="Another search box" />

jQuery 根据下拉菜单中的选择显示/隐藏表单字段

$(document).ready(function() {
	$('#form-btw').hide(); //hide field on start
	
	$('#Klant').change(function() {
 
	 var $index = $('#Klant').index(this);
	 
	 if($('#Klant').val() != 'professional') { //if this value is NOT selected
	 $('#form-btw').hide(); //this field is hidden
	 } 
	 else {
	 $('#form-btw').show();//else it is shown
	 
	 }
        });
 });

---

<select name="Klant" id="Klant">
  <option id="field-particulier" value="particulier">Particulier</option>
  <option id="field-professional" value="professional">Professional</option>
</select>

<input name="BTW" type="text" class="form-text" id="BTW" />

jQuery 图像替换库

//http://www.webdesignerwall.com/tutorials/jquery-tutorials-for-designers/

$().ready(function() {

  $(".thumbs a").hover(function(){
																	
    var normalPath = $(this).attr("href"); //link on thumb
    var normalAlt = $(this).attr("title"); //alt on thumb
      
    $("#normalImg").attr({ src: normalPath, alt: normalAlt });//swap src of the normal sized image with url from href of the thumbnail
    $("#normalImg").parent().attr({ href: normalPath, alt: normalAlt });////swap href of the normal sized image with url from href of the thumbnail
    });
});

---

<div class="holder">
  <a href="../images/photos/batisse-01.jpg"><img id="normalImg" src="../images/photos/batisse-01.jpg" alt="photo batiment" /></a>
</div>

<ul class="thumbs">
  <li><a href="../images/photos/batisse-01.jpg">
    <img src="../images/photos/batisse-01_thumb.jpg" alt="thumb" />
  </a></li>
  <li><a href="../images/photos/batisse-02.jpg">
    <img src="../images/photos/batisse-02_thumb.jpg" alt="thumb" />
  </a></li>
  <li><a href="../images/photos/batisse-03.jpg">
    <img src="../images/photos/batisse-03_thumb.jpg" alt="thumb" />
  </a></li>
</ul>

JavaScript 下拉验证

jQuery.validator.addMethod(
  			"selectNone",
  				function(value, element) {
				//alert(element.options.selectedIndex);
    				//if (element.value == "blank"){
					if (element.options.selectedIndex == "0"){
      				return false;
    				}
    				else return true;
				},
  				"Please select an option."
			);
			
			$(document).ready(function(){ 
			
   				 
			$("#freshmen").validate({
				  rules: { 
	      			program1: { 
	        			selectNone: true 
    			 	} 
				  }
				 
			});

CSS 使用Sass的跨浏览器CSS渐变

@mixin gradient($first, $second) {
  background: $second;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='$first', endColorstr='$second');
  background: -webkit-gradient(linear, left top, left bottom, from($first), to($second));
  background: -moz-linear-gradient(top,  $first,  $second);
}

.gradient {
  @include gradient(black, white);
}